Skip to content
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

Reduce binary size by moving data definitions out of headers. #40254

Merged
merged 1 commit into from
Aug 4, 2020

Conversation

AustinWise
Copy link
Contributor

Contributes to #39599

@Dotnet-GitSync-Bot
Copy link
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@AustinWise
Copy link
Contributor Author

AustinWise commented Aug 3, 2020

On Windows X64 release, this reduces coreclr.dll by 186kb and clrjit by 10kb. The big reduction comes from DbgIPCEventTypeNames: about 172kb.

On Linux x64 release, this reduces libcorclr.so by 8kb and libmscordbi.so by 23kb.

I added some new .cpp files because I was not sure if there was a better place to put the prime numbers.

@jkotas jkotas requested a review from janvorli August 4, 2020 03:03
@jkotas
Copy link
Member

jkotas commented Aug 4, 2020

@janvorli Is there anything left in this change that you have not addressed already?

@AustinWise
Copy link
Contributor Author

@jkotas It looks like @janvorli got almost everything. The only remaining item is -constexpr mdToken g_tkCorEncodeToken[4] ={mdtTypeDef, mdtTypeRef, mdtTypeSpec, mdtBaseType}; in cor.h. The other thing my change does is move the DbgIPCEventTypeNames array to a .cpp file. @janvorli said he attempted this and it was "ugly and problematic". Perhaps there is something I'm overlooking in my solution.

The g_tkCorEncodeToken change contributes a tiny amount of size reduction (something like less than 1kb). So at this point this PR is more about the esthetics of moving the const data to a .cpp file. Given that DbgIPCEventTypeNames was the vast majority of the size regression, it may be worthwhile to move it.

I have rebased.

@janvorli
Copy link
Member

janvorli commented Aug 4, 2020

Great, I have missed the fact that we already have a shared .cpp file between the debug/ee and debug/di, using the trick of #including a .cpp file to solve the problem.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@janvorli janvorli merged commit 4c18fb2 into dotnet:master Aug 4, 2020
@AustinWise AustinWise deleted the austin/SelectanyFollowup branch August 4, 2020 19:41
Jacksondr5 pushed a commit to Jacksondr5/runtime that referenced this pull request Aug 10, 2020
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@k15tfu
Copy link
Contributor

k15tfu commented Sep 3, 2020

Hi! We use some subset of coreclr headers for Profiling API decls (discussed here #11397), but after moving g_tkCorEncodeToken to .cpp we get undefined references when using CorSigCompressToken.

Are there any other options to keep cor.h independent of other internals? @janvorli @jkotas

I checked that this way works fine and that symbols didn't get duplicated on Linux:

FORCEINLINE const mdToken (&g_tkCorEncodeTokenFn())[4] {
    static const mdToken g_tkCorEncodeToken[4] = {mdtTypeDef, mdtTypeRef, mdtTypeSpec, mdtBaseType};
    return g_tkCorEncodeToken;
}

k15tfu added a commit to k15tfu/runtime that referenced this pull request Sep 3, 2020
…on to keep its definition in cor.h

Fixes undefined references to g_tkCorEncodeToken when using CorSigCompressToken()
in user projects with shared Profiling API headers like cor.h / corprof.h

See dotnet#40254 (comment).
jkotas added a commit that referenced this pull request Sep 3, 2020
…on to keep its definition in cor.h (#41797)

Fixes undefined references to g_tkCorEncodeToken when using CorSigCompressToken()
in user projects with shared Profiling API headers like cor.h / corprof.h

See #40254 (comment).

Co-authored-by: Jan Kotas <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants