Repository navigation
Conversation
meisterT
reviewed
Sep 18, 2026
| JNIEnv* env, jobject instance) { | ||
| return gettid(); | ||
| // Keep TLS initialization out of gettid(), which the signal handler also uses. | ||
| static thread_local const pid_t tid = gettid(); |
Member
There was a problem hiding this comment.
instead of doing this - or in addition? - should we do add a ThreadLocal<Integer> on the Java side?
Use a ThreadLocal<Integer> in CpuProfiler to reuse the native thread ID when registering and restoring StarlarkThread instances. This avoids repeated JNI calls as well as native thread-ID lookups during map_each. Leave the native implementation and signal handler unchanged. Validation: EvalTests and ScriptTest passed. A two-thread check confirmed one native lookup per thread across 2,000 nested registrations. An actual CPU profiling run produced samples with the expected function names. RELNOTES: None
dzbarsky
force-pushed
the
codex/cache-profiler-tid-upstream
branch
from
October 6, 2026 06:31
865777c to
d528eb2
Compare
meisterT
approved these changes
Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cache the native thread ID in a Java
ThreadLocal<Integer>inCpuProfiler. Repeated registration and restoration ofStarlarkThreadnow reuse the cached ID, avoiding both JNI calls and native thread-ID lookups. The C++ implementation is unchanged.Starlark
map_eachrepeatedly registers and restores the current thread while CPU profiling is enabled.Validation:
EvalTestsandScriptTestpassed. A two-thread check confirmed one native lookup per thread across 2,000 nested registrations, and a CPU profiling run produced 207 samples with the expected function names. Google Java Format andgit diff --checkpassed.RELNOTES: None
-zbarskybot