Skip to content

perf: skip unused callers JSON decode in ProfileStats#2137

Merged
KRRT7 merged 1 commit intoperf/discovery-ast-cachefrom
cf-2132-skip-callers-json-decode
May 8, 2026
Merged

perf: skip unused callers JSON decode in ProfileStats#2137
KRRT7 merged 1 commit intoperf/discovery-ast-cachefrom
cf-2132-skip-callers-json-decode

Conversation

@KRRT7
Copy link
Copy Markdown
Collaborator

@KRRT7 KRRT7 commented May 7, 2026

Summary

  • Skip the callers BLOB column in ProfileStats.create_stats() — it was fetched and JSON-decoded for every row but never used by FunctionRanker
  • Eliminates O(n) JSON parsing at ranking startup (the dominant cost in FunctionRanker.__init__)
  • Fixes all 20 pre-existing mypy errors in profile_stats.py by declaring pstats.Stats dynamic attributes

Context

Part of #2132 (E2E performance, item 9). The callers column is written by the tracer but never read back — FunctionRanker.load_function_stats() unpacks it as _callers and discards it, and call_graph.py uses its own query that already excludes the column.

Stack

  1. perf: prefilter files by path before read_text() in discovery #2134 (prefilter) → main
  2. perf: cache file reads and AST parses during discovery pass #2135 (ast-cache) → perf/discovery-prefilter
  3. perf: read JS/TS files once during discovery export checks #2136 (js-read) → perf/discovery-ast-cache
  4. This PRperf/discovery-js-read

Test plan

  • All 6 tests/test_function_ranker.py tests pass
  • mypy clean (0 errors, down from 20 pre-existing)
  • ruff check + format pass

@KRRT7 KRRT7 force-pushed the cf-2132-skip-callers-json-decode branch from 57443fb to bf47a12 Compare May 7, 2026 09:29
@KRRT7 KRRT7 changed the base branch from main to perf/discovery-js-read May 7, 2026 09:29
@KRRT7 KRRT7 force-pushed the perf/discovery-js-read branch from 5ab7ec3 to 084f79c Compare May 7, 2026 16:52
@KRRT7 KRRT7 force-pushed the cf-2132-skip-callers-json-decode branch from bf47a12 to 426c0ff Compare May 7, 2026 16:52
@KRRT7 KRRT7 force-pushed the perf/discovery-js-read branch from 084f79c to 5356817 Compare May 7, 2026 17:30
@KRRT7 KRRT7 force-pushed the cf-2132-skip-callers-json-decode branch 2 times, most recently from 7c12c6c to 89cc54f Compare May 7, 2026 17:42
@KRRT7 KRRT7 force-pushed the perf/discovery-js-read branch from 5356817 to 2d9fd1e Compare May 7, 2026 17:42
The callers BLOB column was fetched and JSON-decoded for every row
during FunctionRanker initialization, but the resulting data was
never accessed — FunctionRanker.load_function_stats() discards it
as `_callers`. This eliminates O(n) JSON parsing at ranking startup.

Also fixes all pre-existing mypy errors in this file by declaring
pstats.Stats attributes that the type stubs don't expose.
@KRRT7 KRRT7 force-pushed the perf/discovery-js-read branch from 2d9fd1e to 39d49b1 Compare May 7, 2026 22:47
@KRRT7 KRRT7 force-pushed the cf-2132-skip-callers-json-decode branch from 89cc54f to 448ff82 Compare May 7, 2026 22:48
@KRRT7 KRRT7 marked this pull request as ready for review May 8, 2026 00:22
@KRRT7 KRRT7 requested a review from misrasaurabh1 as a code owner May 8, 2026 00:22
Base automatically changed from perf/discovery-js-read to perf/discovery-ast-cache May 8, 2026 00:28
@KRRT7 KRRT7 merged commit d906b88 into perf/discovery-ast-cache May 8, 2026
32 of 33 checks passed
@KRRT7 KRRT7 deleted the cf-2132-skip-callers-json-decode branch May 8, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant