Skip to content

perf: read JS/TS files once during discovery export checks#2136

Merged
aseembits93 merged 2 commits intoperf/discovery-ast-cachefrom
perf/discovery-js-read
May 8, 2026
Merged

perf: read JS/TS files once during discovery export checks#2136
aseembits93 merged 2 commits intoperf/discovery-ast-cachefrom
perf/discovery-js-read

Conversation

@KRRT7
Copy link
Copy Markdown
Collaborator

@KRRT7 KRRT7 commented May 7, 2026

Parent PR

#2132 — perf: targeted performance improvements for E2E pipeline hot path

Summary

  • Adds optional source: str | None parameter to _is_js_ts_function_exported() and _is_js_ts_function_exists_but_not_exported()
  • Callers pass pre-read content, falling back to read_file_cached() when not provided
  • Eliminates 2 redundant file reads per JS/TS file during discovery

Changes

  • _is_js_ts_function_exported(): accepts optional source param
  • _is_js_ts_function_exists_but_not_exported(): accepts optional source param
  • Discovery loop passes pre-read JS/TS source to both helpers
  • New test file: tests/test_js_ts_export_helpers.py (15 tests)

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. This PRperf/discovery-ast-cache

KRRT7 added 2 commits May 7, 2026 17:46
The _is_js_ts_function_exported and _is_js_ts_function_exists_but_not_exported
helpers each read the file from disk independently, causing up to 2 extra reads
per file during get_functions_to_optimize. Add an optional `source` parameter
to both functions so callers can pass pre-read content. The main call site now
reads the file once and passes it to both helpers.

Also fixes pre-existing mypy error in _find_all_functions_via_language_support
where discover_functions was called with wrong argument order.

Signatures changed:
- _is_js_ts_function_exported(file_path, function_name, source=None)
- _is_js_ts_function_exists_but_not_exported(file_path, function_name, source=None)
The --file path was calling file.read_text() directly even though
find_all_functions_in_file() already primed the discovery cache.
Now uses read_file_cached() to hit the cache with zero disk I/O.
@KRRT7 KRRT7 force-pushed the perf/discovery-ast-cache branch from beac23d to 93763a3 Compare May 7, 2026 22:47
@KRRT7 KRRT7 force-pushed the perf/discovery-js-read branch from 2d9fd1e to 39d49b1 Compare May 7, 2026 22:47
@KRRT7 KRRT7 marked this pull request as draft May 7, 2026 22:53
@KRRT7 KRRT7 marked this pull request as ready for review May 8, 2026 00:20
@aseembits93 aseembits93 merged commit af2912f into perf/discovery-ast-cache May 8, 2026
56 of 59 checks passed
@aseembits93 aseembits93 deleted the perf/discovery-js-read branch May 8, 2026 00:28
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.

2 participants