This repository was archived by the owner on Nov 1, 2020. It is now read-only.
Optimize ObjectWriter to emit series of bytes#3680
Merged
nattress merged 2 commits intodotnet:masterfrom May 23, 2017
Merged
Conversation
Writing each byte of an `ObjectNode` out to the object file one by one is inefficient. We also cannot emit all the bytes of an `ObjectNode` at once because of the streaming nature of the LLVM API. Relocs, CFI info, and symbol definitions are all interruptions emitted at specific points in the stream. Optimize the current implementation by calculating the longest run of bytes between each required interruption. Testing on a large app, ASP.NET Core, this yields a 4% reduction in total compilation time. The total time to compile (collected in Release mode averaged over 5 runs) decreased from 31611ms to 30345ms. A further gain may be possible when we get a high performance implementation of Span<T>, able to efficiently pin the byte arrays we pass to native.
0f891c4 to
01b35ca
Compare
MichalStrehovsky
approved these changes
May 23, 2017
| } | ||
| } | ||
|
|
||
| public SortedSet<int> ByteInterruptionOffsets => _byteInterruptionOffsets; |
Member
There was a problem hiding this comment.
This is unnecessary. You're accessing the property from a static method on ObjectWriter. The underlying field is accessible too.
|
|
||
| unsafe | ||
| { | ||
| // Todo: Use Span<T> instead once it's available to us in this repo |
Member
There was a problem hiding this comment.
What's the advantage of using Span here?
Contributor
Author
There was a problem hiding this comment.
It should save using unsafe because we can take pass a slice to native.
| unsafe | ||
| { | ||
| // Todo: Use Span<T> instead once it's available to us in this repo | ||
| fixed (byte* pContents = nodeContents.Data) |
Member
There was a problem hiding this comment.
Nit: this can be pContents = &nodeContents.Data[i] (with the +1 deleted below) - this style prevents the fixed statement from generating an extra null check
* Remove unnecessary property * Slightly more efficient fixed statement
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Writing each byte of an
ObjectNodeout to the object file one by oneis inefficient. We also cannot emit all the bytes of an
ObjectNodeatonce because of the streaming nature of the LLVM API. Relocs, CFI info,
and symbol definitions are all interruptions emitted at specific points
in the stream. Optimize the current implementation by calculating the
longest run of bytes between each required interruption.
Testing on a large app, ASP.NET Core, this yields a 4% reduction in
total compilation time. The total time to compile (collected in Release
mode averaged over 5 runs) decreased from 31611ms to 30345ms. A further
gain may be possible when we get a high performance implementation of
Span, able to efficiently pin the byte arrays we pass to native.