extracted code to prevent duplicated execution of string index search - #13
Merged
Merged
Conversation
Member
|
Thanks for your contribution and great thinking @M-T3K! I'll review and test this locally later. |
Member
|
Code looks good - good to not redo work when parsing. Ran benchmarks against a large Elixir codebase. This resulted in a minor improvement. Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note: Apologies, I found no PR format established for the project.
This PR is about avoiding duplicate work by extracting the common calls accross
parser.ExtractArity(line, name)andparser.CountDefaultParams(line, name). to the string functionsstrings.Index(line, funcName)andparenIdx := strings.IndexByte(rest, '('). String functions are typically considered expensive, as require browsing & comparing many bytes.Consequences and implications: since the code was being run twice (and in every case that CountDefaultParams was called, ExtractArity had been called beforehand, meaning it happened quite often), by isolating the code that run twice we can avoid the expensive, constant string index operations, reducing in less instructions.
Implementation:
parser.ExtractArity(line, name)&parser.CountDefaultParams(line, name), as they were being exported. I adapt them to call to the new functions.Note
Low Risk
Low risk refactor limited to parsing helpers for function arity/default-parameter detection; main risk is subtle behavior drift in edge-case Elixir function definitions.
Overview
Reduces duplicated string scanning when parsing Elixir function definitions by extracting shared lookup logic into
parser.FindParamContentand splitting computation intoArityFromParams/DefaultsFromParams.Updates both the indexer (
ParseText) and LSP buffer scanning (FindBufferFunctions) to reuse the extracted parameter substring rather than recomputing arity and default counts separately, while keeping the existing exported APIsExtractArityandCountDefaultParamsas thin wrappers.Reviewed by Cursor Bugbot for commit 8571a67. Bugbot is set up for automated code reviews on this repo. Configure here.