Skip to content

Reduce per-token grouping primitive work - #880

Open
alexander-beedie wants to merge 1 commit into
andialbrecht:masterfrom
alexander-beedie:perf/per-token-overhead
Open

Reduce per-token grouping primitive work#880
alexander-beedie wants to merge 1 commit into
andialbrecht:masterfrom
alexander-beedie:perf/per-token-overhead

Conversation

@alexander-beedie

@alexander-beedie alexander-beedie commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Per-token grouping optimisation/streamlining:

  • Token.__init__ resolved is_keyword, is_whitespace, and is_newline with three ttype tests per token built; these flags are now snapshotted per ttype.

  • token_next_by() built a fresh lambda per call for _token_matching(), two Python calls per token visited; now scans directly.

  • group_functions() upper-cased each token once per keyword compared against, rather than once per token.

Results

  • From cProfile, one parse of the 70.3 kB analytics payload:

    | frame                                    | master                 | this branch            |
    |------------------------------------------|------------------------|------------------------|
    | _TokenType.__contains__                  | 305,465 calls, 0.035 s | 180,437 calls, 0.022 s |
    | Token.__init__                           | 41,676 calls, 0.015 s  | 41,676 calls, 0.008 s  |
    | token_next_by + lambda + _token_matching | 0.088 s                | 0.040 s                |
    
  • All 15 benchmark vectors improve; varies between 1.01x to 1.14x faster, with an overall mean speedup of ~1.08x.

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.20%. Comparing base (111b35c) to head (fbb665d).
⚠️ Report is 25 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #880      +/-   ##
==========================================
+ Coverage   97.13%   97.20%   +0.07%     
==========================================
  Files          31       31              
  Lines        3663     3799     +136     
  Branches      328      347      +19     
==========================================
+ Hits         3558     3693     +135     
- Misses         63       65       +2     
+ Partials       42       41       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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