Closed Bug 1841030 Opened 2 years ago Closed 9 months ago

mozilla::MarkerThreadId::CurrentThread is slow

Categories

(Core :: Gecko Profiler, defect, P2)

defect

Tracking

()

RESOLVED FIXED
128 Branch
Tracking Status
firefox128 --- fixed

People

(Reporter: julienw, Assigned: jcristau)

References

Details

(Whiteboard: [fxp] [sp3])

Attachments

(1 file)

I noticed a large profiler overhead in https://share.firefox.dev/3PRC02T while profiling a speedometer 3 workload.

From this profile, mozilla::MarkerThreadId::CurrentThread seems to be very visible especially (in addition to the usual suspects around capturing a backtrace in a buffer).

According to padenot, we should look at using pthread_self instead of gettid (that does a syscall):

syscall(SYS_gettid) -- took: 513.187 ms [0.513187us per iteration]
pthread_self -- took: 0 ms [0us per iteration]
11044057845185138688
getttid -- took: 504.234 ms [0.504234us per iteration]
11044058531219138688
See Also: → 1721569

See also bug 1721569 which has some prior thoughts on this.

Assignee: nobody → canaltinova
Status: NEW → ASSIGNED

The severity field is not set for this bug.
:canova, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(canaltinova)
Severity: -- → S3
Flags: needinfo?(canaltinova)
Priority: -- → P1

I experimented using pthread_self instead of gettid at the time but stopped working on it after encountering some issues:

  1. pthread_self returns an opaque value as oppose to gettid. It might make it harder to see when we need the real tid number after capturing a profile.
  2. If I remember correctly, it broke some things in the frontend. I was suspecting that the number wasn't getting serialized properly into the buffer.

Although second issue can be solved quickly, I still have doubts on the first one. Julien suggested that we could use a thread local storage for this as well to make the consecutive accesses a lot faster. It's worth experimenting with that.

Assignee: canaltinova → nobody
Status: ASSIGNED → NEW
Priority: P1 → P2
Assignee: nobody → jcristau
Status: NEW → ASSIGNED
Assignee: jcristau → nobody
Status: ASSIGNED → NEW
Assignee: nobody → jcristau
Attachment #9393498 - Attachment description: Bug 1841030 - cache the thread id in thread-local storage (WIP) → Bug 1841030 - cache the thread id in thread-local storage
Status: NEW → ASSIGNED

Profiling: https://browserbench.org/Speedometer3.0/?iterationCount=20&suite=TodoMVC-Lit

Profile from latest central: https://share.firefox.dev/3QJdkJ8
Profile with the patch: https://share.firefox.dev/3wolcZX

We can clearly see that the syscall function is much less present. Also the profiler category goes from 12% to 7.7% (-34%).

Nazım and I were curious about Android, so here is a profile on the same workload on firefox Nightly (build from May 8) on my Android phone (Android 12):
https://share.firefox.dev/4dCUzkA

It looks like all profiler-related syscall calls come from the backtrace capture, no gettid spotted there.

Pushed by jcristau@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f8f4ab08cbd0 cache the thread id in thread-local storage r=profiler-reviewers,canaltinova
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 128 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: