-
Notifications
You must be signed in to change notification settings - Fork 91
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
Improve performance of the parser's failure path #374
Conversation
* Previously, an exception was instantiated on each ParseError and the parsing failure was completely dominated by 'fillInStacktrace' method * Now all exception messages are aggregated into a single message and only one instance of ParseException is thrown * An improvement on the basic benchmark is ~300%
A few things:
|
As I've had to write a lot of various datetime formats and check why they don't work, I was consistently frustrated by Java's nonchalant "I can't parse the passed string starting from character 14." Why can't it? What did it expect, what did it get? So, these messages are for when you write a format and aren't sure why it doesn't work. The messages are sorted so that the most successful parsing paths are at the top. You're more likely to be interested in the format that almost worked than the format that failed immediately, though there are some exceptions to this.
Sure. Also, if these exceptions are such a bother performance-wise, then we can rework the code to throw one exception fewer: let |
Thanks, that's an important piece of trivia, I've added the comment.
I (or somebody else) will handle it in a separate PR. |
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.
Nice race condition!
The changes are quite code-local and worth doing -- we are basically avoiding redundant work and making a vector for potential denial of service attacks much less.
Benchmark:
Profile before:
![image](https://private-user-images.githubusercontent.com/2780116/316098239-486db145-a27d-4cb8-b58b-cc3f2f65eac7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5MjA5NzAsIm5iZiI6MTcxOTkyMDY3MCwicGF0aCI6Ii8yNzgwMTE2LzMxNjA5ODIzOS00ODZkYjE0NS1hMjdkLTRjYjgtYjU4Yi1jYzNmMmY2NWVhYzcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQU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