Skip to content
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
nattress:faster_objwriter
May 23, 2017
Merged

Optimize ObjectWriter to emit series of bytes#3680
nattress merged 2 commits intodotnet:masterfrom
nattress:faster_objwriter

Conversation

@nattress
Copy link
Contributor

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, able to efficiently pin the byte arrays we pass to native.

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.
}
}

public SortedSet<int> ByteInterruptionOffsets => _byteInterruptionOffsets;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the advantage of using Span here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@nattress nattress merged commit a549ddd into dotnet:master May 23, 2017
@nattress nattress deleted the faster_objwriter branch May 23, 2017 23:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants