feat(export): add --analyze-config function-call profiler#6
Closed
julienduchesne wants to merge 1 commit into
Closed
feat(export): add --analyze-config function-call profiler#6julienduchesne wants to merge 1 commit into
julienduchesne wants to merge 1 commit into
Conversation
Add an opt-in Jsonnet function-call profiler to `rtk export`, enabled via `--analyze-config <file.json>`. The config requires `output_file` and optionally accepts `sort_by` (total/self/calls), `total_time_threshold`, and `self_time_threshold` (milliseconds). Profiling is gated by a single relaxed atomic, so the normal path is unaffected. Each thread accumulates per-function call counts and timings in thread-local storage and merges into a global aggregate once per environment evaluation, avoiding per-call locking. Inclusive time is recursion-corrected (only the outermost frame of a function contributes) so recursive helpers are not multiply-counted. Co-authored-by: Cursor <cursoragent@cursor.com>
Benchmark Results
Full results available in workflow artifacts. Benchmark run on commit |
juliajohannesen
left a comment
There was a problem hiding this comment.
Wouldn't this be better as an option that enables dynamic tracing spans? IE using the --analyze-config has the program start with a custom tracer that captures function call spans from jrsonnet?
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.
Summary
Add an opt-in Jsonnet function-call profiler to
rtk exportso it's easy to see which functions dominate an evaluation. Enable it with--analyze-config <file.json>, where the config selects how results are ranked and where they're written.output_file(required), plus optionalsort_by(total(default),self,calls),total_time_threshold, andself_time_threshold(both in milliseconds, default0)Context
The single choke point for every Jsonnet call (
FuncVal::evaluate) is wrapped with enter/exit timing. Each worker thread accumulates per-function counts and timings in thread-local storage and merges into a shared aggregate once per environment evaluation, so there's no per-call locking and the parallel export path stays fast.Inclusive ("total") time is recursion-corrected: only the outermost frame of a given function on the stack contributes, so a recursive helper isn't counted once per stack level. Without this, a deeply recursive tokenizer showed a nonsensical 277s total (far above wall-clock); after the fix its caller correctly ranks above it and the numbers reflect the real call hierarchy.
Made with Cursor