Skip to content

Cache the Starlark profiler's native thread ID - #31185

Open
dzbarsky wants to merge 1 commit into
bazelbuild:masterfrom
dzbarsky:codex/cache-profiler-tid-upstream
Open

dzbarsky wants to merge 1 commit into
bazelbuild:masterfrom
dzbarsky:codex/cache-profiler-tid-upstream

Conversation

@dzbarsky

@dzbarsky dzbarsky commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Description

Cache the native thread ID in CpuProfilerNativeSupportImpl.getThreadId using a function-local thread_local constant. Keep gettid() uncached because onsigprof also calls it, so the signal handler never initializes thread-local storage.

Motivation

Starlark map_each repeatedly registers and restores the current thread. Caching the native thread ID avoids a system call on each registration.

In an action that generates a large number of mapped arguments to ctx.actions.args with Starlark profiling enabled, median argument expansion fell from 6.552s to 5.850s.

Build API Changes

No.

Release Notes

RELNOTES: None

Starlark map_each repeatedly registers and restores the current thread.
Cache its native ID in the JNI entrypoint to avoid repeated syscalls;
leave the asynchronous signal handler unchanged.
@github-actions github-actions Bot added team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel awaiting-review PR is awaiting review from an assigned reviewer labels Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer team-Starlark-Interpreter Issues involving the Starlark interpreter used by Bazel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant