⚡ Bolt: Replace indexOf with inline checks for performance#28
⚡ Bolt: Replace indexOf with inline checks for performance#28ericbfriday wants to merge 1 commit into
Conversation
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes luaparse.js hot-path character checks by replacing single-character String.prototype.indexOf membership tests with direct inline === comparisons, aiming to improve lexer/tokenization throughput.
Changes:
- Replaced several single-character
'.indexOf(...) >= 0'checks with inline===comparisons in numeric literal parsing and other parser helpers. - Added a short internal note under
.jules/documenting the optimization rationale and guidance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| luaparse.js | Replaces single-character indexOf checks with direct equality comparisons in lexer/parser hot paths. |
| .jules/bolt.md | Adds a brief markdown note documenting the performance rationale and preferred pattern. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var ch4 = input.charAt(index); | ||
| if (ch4 === 'l' || ch4 === 'L') { |
| if (chSign1 === '+' || chSign1 === '-') | ||
| binarySign = ('+' === input.charAt(index++)) ? 1 : -1; |
💡 What: Replaced single-character
String.prototype.indexOfcalls inluaparse.jswith direct inline equality (===) checks.🎯 Why: In critical paths like lexing/token generation,
String.prototype.indexOfintroduces function call overhead that impacts parse speed. V8 handles simple inline branching and strict equality comparisons much faster.📊 Impact: Increases parsing throughput. Benchmarks run locally showed an improvement from ~299 ops/sec to ~309 ops/sec.
🔬 Measurement: Verify functionality with
npm run test(all 2447 tests pass). Runnpm run bench:luastto observe parsing speed improvements.PR created automatically by Jules for task 17375214573282474445 started by @ericbfriday