Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memoize magic comment regex #944

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Conversation

vinistock
Copy link
Member

Motivation

I was doing some profiling of the indexing process and discovered we were spending about 7-10 seconds inside the magic_comment_regex method.

I don't know why it's so expensive to instantiate that regex, but there's also no point in creating it every time since it's always the same one.

With memoization this is 40x faster than the previous implementation.

Implementation

Just memoized the regex.

@vinistock vinistock added this to the 2023-Q3 milestone Aug 29, 2023
@vinistock vinistock self-assigned this Aug 29, 2023
@vinistock vinistock requested a review from a team as a code owner August 29, 2023 15:13
@github-actions
Copy link
Contributor

Benchmark results in seconds (slowest at top)

          textDocument/completion average: 0.231211 std_dev: 0.003845
          textDocument/diagnostic average: 0.051916 std_dev: 0.012414
          textDocument/definition average: 0.005973 std_dev: 0.00332
      textDocument/selectionRange average: 0.005252 std_dev: 0.000803
   textDocument/documentHighlight average: 0.003328 std_dev: 0.00036
 textDocument/semanticTokens/full average: 0.003268 std_dev: 0.00043
      textDocument/documentSymbol average: 0.003161 std_dev: 0.000351
        textDocument/foldingRange average: 0.003122 std_dev: 0.00025
            textDocument/codeLens average: 0.003105 std_dev: 0.000238
        textDocument/documentLink average: 0.0031 std_dev: 0.000342
textDocument/semanticTokens/range average: 0.002112 std_dev: 0.000223
               codeAction/resolve average: 0.001797 std_dev: 0.000154
               textDocument/hover average: 0.001761 std_dev: 0.000159
           textDocument/inlayHint average: 0.001727 std_dev: 0.000184
          textDocument/formatting average: 0.001098 std_dev: 0.000349
    textDocument/onTypeFormatting average: 0.001068 std_dev: 0.000134
          textDocument/codeAction average: 0.001056 std_dev: 0.000104


================================================================================
Comparison with main branch:

 textDocument/semanticTokens/full unchanged
textDocument/semanticTokens/range unchanged
      textDocument/documentSymbol unchanged
        textDocument/foldingRange unchanged
          textDocument/formatting unchanged
          textDocument/diagnostic unchanged
        textDocument/documentLink unchanged
           textDocument/inlayHint unchanged
      textDocument/selectionRange unchanged
   textDocument/documentHighlight unchanged
               textDocument/hover unchanged
          textDocument/codeAction unchanged
    textDocument/onTypeFormatting unchanged
               codeAction/resolve unchanged
          textDocument/completion faster by 2.392 %
            textDocument/codeLens unchanged
          textDocument/definition unchanged


================================================================================
Missing benchmarks:

RubyLsp::Requests::ShowSyntaxTree

@vinistock vinistock merged commit e0a081b into main Aug 29, 2023
31 checks passed
@vinistock vinistock deleted the vs/memoize_magic_comment_regex branch August 29, 2023 15:34
andyw8 pushed a commit that referenced this pull request Sep 5, 2023
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