-
Notifications
You must be signed in to change notification settings - Fork 20
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
Use a profiler to improve linker performance #291
Merged
Merged
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
1. ast.NoSourceNode has a pointer receiver, so wrapping one in an ast.Node interface value doesn't incur an allocation. Also updates parser.ParseResult to refer to a single *ast.NoSourceNode, instead of allocating one in each call to get a node value. The NoSourceNode's underlying type is now FileInfo so that it can be allocation-free, even for the NodeInfo method (which previously was allocating a new FileInfo each time). 2. Don't allocate a slice to hold the set of checked files for each element being resolved. Instead, we allocate a single slice up front, and use that throughout. 3. Don't pro-actively allocate strings that only are used for error messages; instead defer construction of the change to the construction of the error.
emcfarlane
approved these changes
Apr 22, 2024
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.
lgtm!
Revert "try out map for tracking the checked set, instead of slice" This reverts commit 89cc7b1.
kralicky
pushed a commit
to kralicky/protocompile
that referenced
this pull request
May 19, 2024
After measuring the impact of bufbuild#286, bufbuild#287, and bufbuild#290 and seeing it to be too modest. I decided to use a memory profiler, and it found "the good stuff". These changes had the largest impact on allocations and performance. When linking inputs that come from descriptor protos (as opposed to inputs that are compiled from sources and have ASTs), this resulted in a 23% reduction in latency and 70% reduction in allocations. This change features the following improvements: 1. `ast.NoSourceNode` now has a pointer receiver, so wrapping one in an `ast.Node` interface value doesn't incur an allocation to put the value on the heap. This also updates `parser.ParseResult` to refer to a single `*ast.NoSourceNode` when it has no AST, instead of allocating one in each call to get a node value. The `NoSourceNode`'s underlying type is now `ast.FileInfo` so that it can be allocation-free, even for the `NodeInfo` method (which previously was allocating a new `FileInfo` each time). 3. Don't allocate a slice to hold the set of checked files for each element being resolved. Instead, we allocate a single slice up front, and re-use that throughout. 4. Don't pro-actively allocate strings that only are used for error messages; instead defer construction of the change to the construction of the error. (cherry picked from commit 016b009)
kralicky
pushed a commit
to kralicky/protocompile
that referenced
this pull request
Jun 8, 2024
After measuring the impact of bufbuild#286, bufbuild#287, and bufbuild#290 and seeing it to be too modest. I decided to use a memory profiler, and it found "the good stuff". These changes had the largest impact on allocations and performance. When linking inputs that come from descriptor protos (as opposed to inputs that are compiled from sources and have ASTs), this resulted in a 23% reduction in latency and 70% reduction in allocations. This change features the following improvements: 1. `ast.NoSourceNode` now has a pointer receiver, so wrapping one in an `ast.Node` interface value doesn't incur an allocation to put the value on the heap. This also updates `parser.ParseResult` to refer to a single `*ast.NoSourceNode` when it has no AST, instead of allocating one in each call to get a node value. The `NoSourceNode`'s underlying type is now `ast.FileInfo` so that it can be allocation-free, even for the `NodeInfo` method (which previously was allocating a new `FileInfo` each time). 3. Don't allocate a slice to hold the set of checked files for each element being resolved. Instead, we allocate a single slice up front, and re-use that throughout. 4. Don't pro-actively allocate strings that only are used for error messages; instead defer construction of the change to the construction of the error. (cherry picked from commit 016b009)
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.
After measuring the impact of #286, #287, and #290 and seeing it to be too modest. I decided to use a memory profiler, and it found "the good stuff".
These changes had the largest impact on allocations and performance. When linking inputs that come from descriptor protos (as opposed to inputs that are compiled from sources and have ASTs), this reduced the time per operation by 23% and the allocations by 70%. (Each operation consisted of linking all of the descriptors in the full
googleapis
module, which has 1000s of files. It reduced the runtime from 260ms to 200ms and reduced allocations from 3.4 million down to 1 million).before:
after:
This change features the following improvements:
ast.NoSourceNode
now has a pointer receiver, so wrapping one in anast.Node
interface value doesn't incur an allocation to put the value on the heap. This also updatesparser.ParseResult
to refer to a single*ast.NoSourceNode
when it has no AST, instead of allocating one in each call to get a node value. TheNoSourceNode
's underlying type is nowast.FileInfo
so that it can be allocation-free, even for theNodeInfo
method (which previously was allocating a newFileInfo
each time).NoSourceNode
is not used. But it does help when the input to the linker is a descriptor proto instead of source (i.e. aparser.ResultWithoutAST
).Below are the latest benchmarks for this repo, before and after this branch and the previous three PRs. Like with the first bullet above, the net effect of these changes is quite small in the context of a normal, complete compile operation (which does a lot more than just linking) -- the difference is measurable but almost inconsequential. However, it is significant when just linking descriptor protos into descriptors (see stats in first paragraph).
before:
after: