perf: encode file contents once in tree-sitter scoring - #984
Closed
aliangm wants to merge 3 commits into
Closed
Conversation
new_content was encoded to UTF-8 twice — once for the MAX_FILE_SIZE_BYTES size check and again inside parse_code() before tree-sitter parsing. old_content was likewise re-encoded inside parse_code(). Encode each side once at the call site and pass bytes through. parse_code() and score_tree_diff() now accept Union[str, bytes] so existing str callers (tests) keep working unchanged. Also reorders the skip checks so unsupported extensions short-circuit before any encoding work.
Collaborator
|
fix CI |
Contributor
Author
|
@anderdc Fixed CI, ty |
Collaborator
|
fix conflicts |
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.
Description:
Summary
new_contentwas encoded to UTF-8 twice — once for theMAX_FILE_SIZE_BYTESsize check at tree_sitter_scoring.py:312 and again insideparse_code()at line 77.old_contentwas likewise re-encoded insideparse_code().calculate_token_score_from_file_changes()and passbytesthrough.parse_code()andscore_tree_diff()now acceptUnion[str, bytes]so existingstrcallers (tests) keep working unchanged.supports_tree_sitter(ext)short-circuits before any encoding — unsupported extensions no longer pay encode cost.Behavior change
A file that is both unsupported-extension and larger than
MAX_FILE_SIZE_BYTESwill now log asskipped-unsupportedinstead ofskipped-large. Same final outcome (skipped, score 0), only the metric label differs.Test plan
pytest tests/validator/test_token_scoring_integration.py)..pyfile is skipped asskipped-large(size check still effective).skipped-unsupported(new behavior).Fixes #983