-
Notifications
You must be signed in to change notification settings - Fork 213
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
AST Tweaks #551
Merged
Merged
AST Tweaks #551
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node is a 56B struct that is constantly in the hot path. Passing nodes around by copy had a cost that started to add up. This change replaces them by pointers. Using unsafe pointer arithmetic and converting sibling/child indexes to relative offsets, it removes the need to carry around a pointer to the root of the tree. This saves 8B per Node. This space will be used to store an extra []byte slice to provide contextual error handling on all nodes, including the ones whose data is different than the raw input (for example: strings with escaped characters), while staying under the size of a cache line. --- ``` name old time/op new time/op delta UnmarshalDataset/config 28.6ms ± 1% 26.0ms ± 1% -9.03% (p=0.000 n=9+10) UnmarshalDataset/canada 114ms ± 0% 100ms ± 2% -12.23% (p=0.000 n=10+10) UnmarshalDataset/citm_catalog 38.5ms ± 2% 30.1ms ± 0% -21.87% (p=0.000 n=10+10) UnmarshalDataset/twitter 14.6ms ± 1% 11.3ms ± 1% -23.01% (p=0.000 n=10+10) UnmarshalDataset/code 127ms ± 1% 116ms ± 1% -8.32% (p=0.000 n=9+10) UnmarshalDataset/example 193µs ± 0% 167µs ± 0% -13.73% (p=0.000 n=10+10) Unmarshal/SimpleDocument/struct 707ns ± 2% 540ns ± 0% -23.64% (p=0.000 n=10+10) Unmarshal/SimpleDocument/map 1.00µs ± 2% 0.86µs ± 1% -13.49% (p=0.000 n=10+10) Unmarshal/ReferenceFile/struct 48.8µs ± 3% 41.2µs ± 0% -15.51% (p=0.000 n=10+8) Unmarshal/ReferenceFile/map 77.5µs ± 0% 70.6µs ± 0% -8.93% (p=0.000 n=9+10) Unmarshal/HugoFrontMatter 15.9µs ± 0% 14.4µs ± 0% -9.27% (p=0.000 n=8+10) name old speed new speed delta UnmarshalDataset/config 36.7MB/s ± 1% 40.4MB/s ± 1% +9.92% (p=0.000 n=9+10) UnmarshalDataset/canada 19.3MB/s ± 0% 22.0MB/s ± 2% +13.94% (p=0.000 n=10+10) UnmarshalDataset/citm_catalog 14.5MB/s ± 2% 18.5MB/s ± 0% +27.98% (p=0.000 n=10+10) UnmarshalDataset/twitter 30.2MB/s ± 1% 39.2MB/s ± 1% +29.90% (p=0.000 n=10+10) UnmarshalDataset/code 21.2MB/s ± 1% 23.1MB/s ± 1% +9.08% (p=0.000 n=9+10) UnmarshalDataset/example 41.9MB/s ± 0% 48.6MB/s ± 0% +15.91% (p=0.000 n=10+10) Unmarshal/SimpleDocument/struct 15.6MB/s ± 2% 20.4MB/s ± 0% +30.99% (p=0.000 n=10+9) Unmarshal/SimpleDocument/map 11.0MB/s ± 2% 12.7MB/s ± 0% +15.50% (p=0.000 n=10+9) Unmarshal/ReferenceFile/struct 108MB/s ± 3% 127MB/s ± 0% +18.32% (p=0.000 n=10+8) Unmarshal/ReferenceFile/map 67.6MB/s ± 0% 74.3MB/s ± 0% +9.81% (p=0.000 n=9+10) Unmarshal/HugoFrontMatter 34.4MB/s ± 0% 37.9MB/s ± 0% +10.21% (p=0.000 n=8+10) name old alloc/op new alloc/op delta UnmarshalDataset/config 5.91MB ± 0% 5.90MB ± 0% -0.27% (p=0.000 n=10+10) UnmarshalDataset/canada 84.4MB ± 0% 73.8MB ± 0% -12.49% (p=0.000 n=8+8) UnmarshalDataset/citm_catalog 35.6MB ± 0% 30.3MB ± 0% -15.08% (p=0.000 n=10+10) UnmarshalDataset/twitter 13.5MB ± 0% 11.3MB ± 0% -16.10% (p=0.000 n=10+10) UnmarshalDataset/code 22.2MB ± 0% 22.2MB ± 0% -0.00% (p=0.000 n=10+10) UnmarshalDataset/example 193kB ± 0% 160kB ± 0% -16.74% (p=0.000 n=10+10) Unmarshal/SimpleDocument/struct 597B ± 0% 533B ± 0% -10.72% (p=0.000 n=10+10) Unmarshal/SimpleDocument/map 973B ± 0% 909B ± 0% -6.58% (p=0.000 n=10+10) Unmarshal/ReferenceFile/struct 11.6kB ± 0% 11.3kB ± 0% -2.21% (p=0.000 n=10+10) Unmarshal/ReferenceFile/map 28.9kB ± 0% 28.7kB ± 0% -0.88% (p=0.000 n=9+10) Unmarshal/HugoFrontMatter 7.39kB ± 0% 7.26kB ± 0% -1.73% (p=0.000 n=9+10) name old allocs/op new allocs/op delta UnmarshalDataset/config 233k ± 0% 233k ± 0% ~ (p=1.000 n=10+10) UnmarshalDataset/canada 782k ± 0% 782k ± 0% ~ (all equal) UnmarshalDataset/citm_catalog 192k ± 0% 192k ± 0% ~ (p=0.059 n=10+8) UnmarshalDataset/twitter 56.9k ± 0% 56.9k ± 0% ~ (p=0.878 n=10+10) UnmarshalDataset/code 1.06M ± 0% 1.06M ± 0% ~ (all equal) UnmarshalDataset/example 1.36k ± 0% 1.36k ± 0% ~ (all equal) Unmarshal/SimpleDocument/struct 7.00 ± 0% 7.00 ± 0% ~ (all equal) Unmarshal/SimpleDocument/map 12.0 ± 0% 12.0 ± 0% ~ (all equal) Unmarshal/ReferenceFile/struct 182 ± 0% 182 ± 0% ~ (all equal) Unmarshal/ReferenceFile/map 649 ± 0% 649 ± 0% ~ (all equal) Unmarshal/HugoFrontMatter 143 ± 0% 143 ± 0% ~ (all equal) ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ast.Node
as pointers, not copies.[]byte
toast.Node
to have both the raw input (for error reporting) and the actual parsed value (for strings with escaped characters).ast.Reference
from astruct
to a singleint
to save space.