-
Notifications
You must be signed in to change notification settings - Fork 350
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
eskip: improve lexer performance 2 #2870
Conversation
Add a benchmark for parsing 10000 routes. Signed-off-by: Alexander Yastrebov <[email protected]>
func scanSymbol(code string) (t token, rest string, err error) { | ||
t.id = symbol | ||
t.val, rest = scanWhile(code, isSymbolChar) | ||
for i := 0; i < len(code); i++ { | ||
if !isSymbolChar(code[i]) { | ||
t.val, rest = code[0:i], code[i:] | ||
return | ||
} | ||
} | ||
t.val, rest = code, "" | ||
return | ||
} |
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.
* use plain ascii instead of unicode package * use loop for scanSymbol * call scan functions directly instead of selectScanner to aid inlining ``` goos: linux goarch: amd64 pkg: github.com/zalando/skipper/eskip │ HEAD~1 │ HEAD │ │ sec/op │ sec/op vs base │ ParsePredicates-8 9.637µ ± 11% 8.894µ ± 4% -7.71% (p=0.001 n=10) Parse-8 329.1m ± 4% 272.7m ± 2% -17.15% (p=0.000 n=10) geomean 1.781m 1.557m -12.56% │ HEAD~1 │ HEAD │ │ B/op │ B/op vs base │ ParsePredicates-8 2.008Ki ± 0% 2.008Ki ± 0% ~ (p=1.000 n=10) Parse-8 49.94Mi ± 0% 49.94Mi ± 0% ~ (p=0.926 n=10) geomean 320.4Ki 320.4Ki -0.00% │ HEAD~1 │ HEAD │ │ allocs/op │ allocs/op vs base │ ParsePredicates-8 33.00 ± 0% 33.00 ± 0% ~ (p=1.000 n=10) ¹ Parse-8 1.100M ± 0% 1.100M ± 0% ~ (p=0.367 n=10) geomean 6.025k 6.025k +0.00% ¹ all samples are equal ``` See previous #2755 Signed-off-by: Alexander Yastrebov <[email protected]>
b039073
to
9a52f75
Compare
func isAlpha(c byte) bool { return unicode.IsLetter(rune(c)) } | ||
func isDigit(c byte) bool { return unicode.IsDigit(rune(c)) } |
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 is equivalent but inlines better since c is byte and unicode.* does internal check for ascii
func isSymbolChar(c byte) bool { return isUnderscore(c) || isAlpha(c) || isDigit(c) } | ||
func isAlpha(c byte) bool { return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') } | ||
func isDigit(c byte) bool { return c >= '0' && c <= '9' } | ||
func isSymbolChar(c byte) bool { return isAlpha(c) || isDigit(c) || isUnderscore(c) } |
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.
Check more frequent class first
👍 |
1 similar comment
👍 |
See previous #2755