"How I made critical code run much faster"
summary
A Node.js SQL-injection detector that runs on every query starts at about 5 ms per execution and becomes a scalability problem as HTTP traffic grows above 10% of requests. Performance improvements include moving closures out of the hot function to avoid repeated redefinition (≈5x win) and replacing repeated string slices with a character-by-character scanSTR no-alloc matcher, dropping per-call time to under 1 ms. Investigation uses Chrome DevTools CPU and heap profilers and uncovers V8 deopt/hidden-class pitfalls that require careful typing to avoid losing optimization.
AI-written summary · about
chapters (13)
- 0:00Introduction and background
- 1:31Initial slow SQL injection code
- 3:19Fixing closure instantiation issue
- 4:22Identifying slowest function part
- 5:04Understanding the parser function
- 8:58Optimizing token checks order
- 10:24Fixing inefficient string slicing
- 12:53V8 optimization limitations
- 15:44Type optimization and deoptimization
- 17:34Shadow classes impact on optimization
- 20:02Key lessons and advice
- 21:49Start with easy optimizations
- 23:14Context and big picture importance
