-
Notifications
You must be signed in to change notification settings - Fork 9
draft: performance refactor #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
Can we split this one? |
| // new value is special using the PHRASES mapping. | ||
| // | ||
| // Example: "UNION" + "ALL" = "UNION ALL" | ||
| func (s *sqliState) merge(tokenA, tokenB *sqliToken) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the changes in this func. Can we add this in a separate PR?
The switch simplifies and it is easier to read.
| for _, ch := range []byte(s.input) { | ||
| if ch == byteSingle { | ||
| hasSingleQuote = true | ||
| break | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strings.IndexByte is faster—often much faster—than a manual for _, ch := range []byte(s) loop.
| for _, ch := range []byte(s.input) { | ||
| if ch == byteDouble { | ||
| hasDoubleQuote = true | ||
| break | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
| var state sqliState // Stack allocation instead of heap | ||
| sqliInit(&state, input, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might make sense.
| for _, ch := range str { | ||
| if ch == '\\' { | ||
| hasBackslash = true | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.



Performance:
Speed: 3-10% faster across all benchmarks
Memory: 0.2-1.1% reduction in bytes allocated
Throughput: 2x (100%+) improvement in operations per second
Other improvements: