-
-
Notifications
You must be signed in to change notification settings - Fork 445
Reduce lexer memory allocs #811
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: master
Are you sure you want to change the base?
Conversation
} | ||
|
||
func (s Source) String() string { | ||
return string(s) | ||
return s.raw | ||
} | ||
|
||
func (s Source) Snippet(line int) (string, 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.
This method is no longer used but I'm keeping it in case someone was using it.
|
||
"github.com/expr-lang/expr/file" | ||
) | ||
|
||
const minTokens = 10 |
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 allows for optimistically allocating tokens. Discussing the "right" value for this parameter can be a loss of time (everyone has an opinion on what should be the "right" value).
The only thing I will hold is that using zero (the default) is the worst of all values because you will likely always need some nodes. It would be very rare that you don't. And the first few times your add a new node with append
then the runtime will just have to copy over and over the same underlying array while it grows the slice.
@@ -335,6 +335,7 @@ literal not terminated (1:10) | |||
früh ♥︎ | |||
unrecognized character: U+2665 '♥' (1:6) | |||
| früh ♥︎ | |||
| .....^ |
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 appeared to be a small bug. In the original code, if it found a rune longer than 1 byte it would skip the indicator line entirely. I imagine that wouldn't be good if we have something like:
let myStr = "Hello, 世界"; someError
In that case it wouldn't put the indicator line because it will find the '世' rune.
Fixes #810
Benchmark results (20% faster, 40% less memory copying, 75% less allocations):
Benchmarks were performed in the
parser/lexer
directory executing the command:The file was renamed to either
old.txt
ornew.txt
, and the comparison was made with:Raw results from old.txt
Raw results from new.txt