⚡ Bolt: [performance improvement] Replace .indexOf on single chars with charCodeAt/=== checks#43
Conversation
…ecks This removes the method call overhead and temp string instantiations when doing single-character matching in the lexer logic.
|
👋 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.
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Imaginary unit number suffix is optional. | ||
| // See http://luajit.org/ext_ffi_api.html#literals | ||
| if ('iI'.indexOf(input.charAt(index) || null) >= 0) { | ||
| if ((input.charCodeAt(index) === 105 || input.charCodeAt(index) === 73)) { |
💡 What: Replaced occurrences of
String.prototype.indexOfbeing used on short 2-character strings to match individual characters (e.g.'xX'.indexOf(c) >= 0) with faster alternatives likec.charCodeAt(0) === 120 || c.charCodeAt(0) === 88andc === 'x' || c === 'X'.🎯 Why: In hot code paths like a parser's character classification,
indexOfintroduces method call overhead. Doing simple strict equality checks or checking character codes is measurably faster in V8 and other modern JS engines.📊 Impact: Micro-benchmark showed
charCodeAtcomparisons being ~4-5x faster thanindexOffor this specific case.npm run bench:luastshowed an improvement (e.g., from ~294 ops/sec to ~306 ops/sec).🔬 Measurement: Verified the improvement in performance locally using a simple loop benchmark, and via the
bench:luastsuite. Verified correctness by running the full test suite (npm run test), which passes 2447 assertions.PR created automatically by Jules for task 5313355218527534274 started by @ericbfriday