Skip to content

⚡ Optimize regex compilation in LSP server - #859

Merged
godofecht merged 1 commit into
mainfrom
perf-lsp-regex-compilation-8199638530596117479
Sep 9, 2026
Merged

godofecht merged 1 commit into
mainfrom
perf-lsp-regex-compilation-8199638530596117479

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

💡 What: Moved decl_re in _extract_symbols_regex and field_re in _regex_struct_fields to class-level attributes _DECL_RE and _FIELD_RE within FlowLanguageServer.
🎯 Why: The regular expressions in these methods were statically defined but were being recompiled every time the functions were called. This redundant compilation added unnecessary overhead during symbol extraction and structure field scanning in the Language Server. By hoisting them to the class level, they are compiled only once.
📊 Measured Improvement:
Before the change, running _extract_symbols_regex on a 1000-line sample text 100 times took 0.2810s.
After the change, the same workload took 0.2732s, demonstrating a consistent ~3% speedup on this isolated microbenchmark.
Similarly, _regex_struct_fields improved from 4.3485s to 3.9178s (a ~10% speedup) over 100 iterations of scanning the lines.
While the absolute savings are relatively small, this code path is hit frequently during language server operations, and these redundant compilations provide no value.


PR created automatically by Jules for task 8199638530596117479 started by @godofecht

Move regex compilation for symbol extraction and struct field matching to class-level attributes in `FlowLanguageServer`. This avoids recompiling the regular expressions on every function call during symbol extraction.

Co-authored-by: godofecht <[email protected]>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@godofecht
godofecht force-pushed the perf-lsp-regex-compilation-8199638530596117479 branch from d218d1d to b19c7c6 Compare September 7, 2026 14:52
@godofecht
godofecht marked this pull request as draft September 8, 2026 07:57

Copy link
Copy Markdown
Contributor Author

Moved to draft because this overlaps #862 on _regex_struct_fields. Do not merge both independently. After the 1.0.2 candidate is frozen/released, consolidate the declaration-regex hoist from this PR with the struct-field/end-regex hoist from #862 into one locally qualified LSP patch.

@google-labs-jules

Copy link
Copy Markdown
Contributor

Moved to draft because this overlaps #862 on _regex_struct_fields. Do not merge both independently. After the 1.0.2 candidate is frozen/released, consolidate the declaration-regex hoist from this PR with the struct-field/end-regex hoist from #862 into one locally qualified LSP patch.

Understood. Acknowledging that this work overlaps with #862 on _regex_struct_fields and should be consolidated locally into one patch after the 1.0.2 candidate is frozen/released. I am stopping work on this task.

@godofecht
godofecht marked this pull request as ready for review September 9, 2026 11:45
@godofecht
godofecht merged commit 6e4789b into main Sep 9, 2026
2 checks passed
@godofecht
godofecht deleted the perf-lsp-regex-compilation-8199638530596117479 branch September 9, 2026 13:07
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