Closed Bug 520172 Opened 15 years ago Closed 15 years ago

gloda indexer stringifies MessagesByMessageIdCallback results for debug even when not in debug mode

Categories

(MailNews Core :: Database, defect)

x86
All
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 3.0rc1

People

(Reporter: smaug, Unassigned)

Details

(Keywords: perf)

Attachments

(2 files)

Shark profile shows that 50% of time is spent under CompletionNotifier::Run()
which then calls some JS. That leads to *very* deep MarkSharpObjects recursion.

Just a guess, something wrong with datastore.js' handleCompletion implementations?
http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/datastore.js#72
http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/datastore.js#275
http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/datastore.js#1229
Summary: [faceted search] Indexing mails is slow → [faceted search] Indexing messages is slow
(leaving [faceted search] in summary for search purposes)
Keywords: perf
OS: Mac OS X → All
Summary: [faceted search] Indexing messages is slow → [faceted search] Gloda Indexing messages is slow
Could you elaborate on the depth of the MarkSharpObjects recursion and provide some analysis as to why it is a bad thing?  If we are not blowing the stack and there's no reason to presume we are creating pathological algorithmic behavior (O(n^2) or worse), I'm not sure this is a bad thing.

We do all kinds of work in handleCompletion because much of our code is asynchronous and dependent on those database notifications for the data it needs to do its work.
(In reply to comment #2)
> Could you elaborate on the depth of the MarkSharpObjects recursion and provide
> some analysis as to why it is a bad thing?
I was just profiling using Shark and noticed that lots of time is spent in
very deep MarkSharpObjects recursion. I don't exactly know why, and what does 
that mean.
But perhaps there is some recursive algorithm which could be changed to iterative. (just guessing...). If iteration is possible, it is quite often
faster than recursion - especially with 1.9.1.x Tracemonkey, which doesn't, IIRC, trace recursion.

> We do all kinds of work in handleCompletion because much of our code is
> asynchronous and dependent on those database notifications for the data it
> needs to do its work.
Right. I understand that, but I was hoping the algorithms could be tweaked a bit.

The new search is awesome, but when I updated my TB build to one which has the
new search, indexing emails took ~8h. That is quite a lot.
smaug found me on IRC and reminded me that MarkSharpObjects is the pretty-printer helper thing and not something related to GC.

There is over-zealous debug in MessagesByMessageIdCallback.  We are trying to stringify the results structure regardless of our debug setting.

Thank you very much for logging this bug, smaug!
Status: NEW → ASSIGNED
Component: Search → Database
Product: Thunderbird → MailNews Core
QA Contact: search → database
Summary: [faceted search] Gloda Indexing messages is slow → gloda indexer stringifies MessagesByMessageIdCallback results for debug even when not in debug mode
Target Milestone: --- → Thunderbird 3.0rc1
Version: unspecified → Trunk
I ran this with my indexing benchmark.  The debug appears to have trivial performance ramifications; the difference basically gets lost in the noise.  I was really hoping that was it.  This makes sense considering the code still should have shown up as a hot-spot last time I killed off over-zealous debug.

Olli, if you can post your shark dump in text form, that could be useful.  It's possible there's some form of edge case happening and that might be useful.  Of course, without the JS stack, it'll be mainly guesswork.
Status: ASSIGNED → NEW
There certainly is no benefit to wastefully doing the stringification, so let's stop doing it when not needed.  Since we're not absolutely sure if the shark trace is pointing out this as a problem or something else, let's see if this makes it go away.
Attachment #404640 - Flags: review?(bienvenu)
Comment on attachment 404640 [details] [diff] [review]
v1 only build the string if it will be used for debug logging

shouldn't this be

if (MBM_LOG.level >= Log4Moz.Level.Debug)

?
(In reply to comment #8)
> (From update of attachment 404640 [details] [diff] [review])
> shouldn't this be
> 
> if (MBM_LOG.level >= Log4Moz.Level.Debug)

No, although that's what I wrote the first time I was fixing the indexer verbose debug :)

From:
http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/log4moz.js#69

  Level: {
    Fatal:  70,
    Error:  60,
    Warn:   50,
    Info:   40,
    Config: 30,
    Debug:  20,
    Trace:  10,
    All:    0,
Attachment #404640 - Flags: review?(bienvenu) → review+
Comment on attachment 404640 [details] [diff] [review]
v1 only build the string if it will be used for debug logging

ah, ok...that's going to take some getting used to :-)
Attachment #404640 - Flags: approval-thunderbird3?
Attachment #404640 - Flags: approval-thunderbird3? → approval-thunderbird3+
pushed attachment 404640 [details] [diff] [review]:
http://hg.mozilla.org/comm-central/rev/1a5f029b9d51

Olli, if you can try again and post the shark trace when this shows up in a new nightly or when you get time to spin your own new build, that would be great.
Now I can't see MarkSharpObjects in the profile anymore.

74.9% of time under CompletionNotifier::Run() is now spent somewhere
in generator_op.
In the earlier profile that was 38.8%, so seems like there is a significant 
improvement.
Since we landed a patch and I don't think there is anything actionable left on the bug (although there is lots of performance work we could do in general), let's mark this fixed.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: