Closed Bug 700217 Opened 15 years ago Closed 11 years ago

nsMemoryReporterManager can spend a bunch of time comparing strings

Categories

(Core :: XPCOM, defect)

9 Branch
x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: bzbarsky, Unassigned)

References

Details

I was trying to profile my browser freezes (in a shark nightly, so no real symbols sadly, so no per-line blame), and one of my profiles I'm seeing 100ms or so spent comparing strings in nsMemoryReporterManager via nsACString::Equals. As far as I can tell, I caught a telemetry ping getting .explicit on it. I'm guessing he relevant code block is the one with this comment: // This is quadratic in the number of explicit NONHEAP reporters, // but there shouldn't be many. I checked, and my opt build has 37 explicit nonheap reporters. That does not seem like enough to spend 100ms in that loop...
I put timing code in nsMemoryReporterManager::GetExplicit and then ran Components.classes["@mozilla.org/base/telemetry-ping;1"].getService(Components.interfaces.nsIObserver).observe(null, "test-ping", "http://localhost:4444"); It takes about 15ms total for me.
I also profiled running that command a bunch of times (Linux-64). I don't see nsACString::Equals in the profile. Here are all the entries of 1% or more: 17.03% threaded-ml [kernel.kallsyms] [k] 0xffffffff81031dba 5.48% threaded-ml libc-2.13.so [.] _IO_vfscanf_internal 2.00% threaded-ml libc-2.13.so [.] __memcmp_sse4_1 1.67% threaded-ml libcairo.so.2.11000.2 [.] 0xf6d5 1.56% threaded-ml libxul.so [.] (anonymous namespace)::CellCallback(JSContext*, void*, void*, JSGCTraceKind, unsigned long) 1.54% threaded-ml firefox [.] arena_salloc 1.44% threaded-ml libpthread-2.13.so [.] __pthread_mutex_lock_internal 1.42% threaded-ml firefox [.] malloc_usable_size 1.38% threaded-ml libxul.so [.] nsACString_internal::Replace(unsigned int, unsigned int, char const*, unsigned int) 1.30% threaded-ml libxul.so [.] void js::gc::ForEachArenaAndCell<js::IterateArenaCallbackOp, js::IterateCellCallbackOp>(JSCompartment*, js::gc::AllocKind, js::IterateArenaCallbackOp, js::IterateCellCallbackOp) 1.01% threaded-ml libxul.so [.] SearchTable(PLDHashTable*, void const*, unsigned int, PLDHashOperator)
Note that in my case the browser may have been under both memory and context-switch pressure...
Weird. Maybe shark is lying to me.... I'll poke around and see what I can find.
I have an idea for avoiding the quadratic case. Whether or not it is a perf problem, disallowing non-leaf reporters (which were introduced in bug 653630) will make GetExplicit and some other things simpler. I just need to work out something for "storage/sqlite"
Depends on: 700508
I just measured, I often had 75--85 non-leaf reporters, resulting in 3500-ish pairwise comparisons.
(In reply to Nicholas Nethercote [:njn] from comment #5) > I have an idea for avoiding the quadratic case. Whether or not it is a perf > problem, disallowing non-leaf reporters (which were introduced in bug > 653630) will make GetExplicit and some other things simpler. Bug 700508 did this.
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Bug 700508 was backed out because it depended on bug 703143, which was also backed out, due to crashes.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
I think this problem is long gone.
Status: REOPENED → RESOLVED
Closed: 14 years ago → 11 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.