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

Refactor TemplateInstance to reduce its size #11368

Merged
merged 9 commits into from
Jul 7, 2020
Merged

Conversation

andralex
Copy link
Member

@andralex andralex commented Jul 3, 2020

This reduces the size of TemplateInstance from 384 bytes to 375 bytes. It does not affect compilation times or memory consumed in my tests on a large project. The impact will come if combined with other size improvements.

@andralex andralex requested review from ibuclaw and RazvanN7 as code owners July 3, 2020 23:40
@dlang-bot
Copy link
Contributor

dlang-bot commented Jul 3, 2020

Thanks for your pull request, @andralex!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11368"

src/dmd/dtemplate.d Outdated Show resolved Hide resolved
src/dmd/dtemplate.d Outdated Show resolved Hide resolved
src/dmd/dtemplate.d Outdated Show resolved Hide resolved
src/dmd/dtemplate.d Outdated Show resolved Hide resolved
Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

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

Need to update headers

@andralex
Copy link
Member Author

andralex commented Jul 3, 2020

@thewilsonator will update the C++ headers once review settles, thanks! @MoonlightSentinel minded your review, thanks.

@ghost
Copy link

ghost commented Jul 4, 2020

from 384 bytes to 375 bytes. It does not affect compilation times or memory

This is because you must reduce the size down to 368 to see an impact (which makes 23 blocks exactly). inuse can be declared as ubyte, which makes 372. If in addition you manage to pack 4 more bytes this would be impactful.

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

OK, so following the recent comments I made inuse one byte large and kept nest 16 bits, of which 3 are taken by flags. Works?

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

Size is 371 now.

@ghost
Copy link

ghost commented Jul 4, 2020

Sorry i was thinking modifications were in TemplateDeclaration hence my previous message could be confusing.
I think that 368 will not be possible then.

@ghost
Copy link

ghost commented Jul 4, 2020

Maybe the solution: inherited member ScopeDsymbol.enflinnum is assigned plenty of times but never used. If you remove it then TemplateInstance size is 363. Also it wont be necessary to use inuse memory to store the set of Flag.

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

Maybe the solution: inherited member ScopeDsymbol.enflinnum is assigned plenty of times but never used. If you remove it then TemplateInstance size is 363. Also it wont be necessary to use inuse memory to store the set of Flag.

Interesting, one step at a time though.

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

@NilsLankila eh, removed endlinnum per your advice. Let's see what @WalterBright says.

@ghost
Copy link

ghost commented Jul 4, 2020

I've tested in another PR (#11369). Maybe you're not browsing using the website but the test suite is broken.
BTW endlinnum was added in #2867

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

I've tested in another PR (#11369). Maybe you're not browsing using the website but the test suite is broken.

OK thanks, I undid my related commit.

@Geod24 Geod24 changed the title Flagpack Refactor TemplateInstance to reduce its size Jul 4, 2020
src/dmd/dtemplate.d Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Jul 4, 2020

@rainers has confirmed that ScopeDsymbol.endlinnum should not be removed, although it's most of the time unsued but when debug info are generated (and codeview only !). Sorry for the wrong track.

@andralex andralex requested a review from WalterBright as a code owner July 4, 2020 18:06
@dnadlinger
Copy link
Member

The C++ headers need updating as well for the changed layout. (None of the fields seem to be used directly from LDC this time, so this is just a matter of avoiding ABI issues down the road.)

@andralex
Copy link
Member Author

andralex commented Jul 4, 2020

The C++ headers need updating as well for the changed layout. (None of the fields seem to be used directly from LDC this time, so this is just a matter of avoiding ABI issues down the road.)

Will do as soon as we settle on the layout.

@andralex
Copy link
Member Author

andralex commented Jul 5, 2020

Operated change on the C++ side as well (blindly), any mistake? Any other places to change?

@dnadlinger
Copy link
Member

Operated change on the C++ side as well (blindly), any mistake? Any other places to change?

Don't think so. You could probably drop the C++ implementations as well; it's unlikely that these members are even used from C++ land.

src/dmd/dtemplate.d Outdated Show resolved Hide resolved
Copy link
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

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

Apart from small nits also mentioned by @dnadlinger, I have some reservations about whether nest and the other bool flags really are mutually exclusive (what happens if I call toChars in the middle of a gdb session after one of the flags has been set?)

src/dmd/template.h Outdated Show resolved Hide resolved
src/dmd/template.h Outdated Show resolved Hide resolved
src/dmd/dtemplate.d Outdated Show resolved Hide resolved
@andralex
Copy link
Member Author

andralex commented Jul 6, 2020

Apart from small nits also mentioned by @dnadlinger, I have some reservations about whether nest and the other bool flags really are mutually exclusive (what happens if I call toChars in the middle of a gdb session after one of the flags has been set?)

They can be used concomitantly. The taken bits are the uppermost ones, whereas the only way nest can be used is by incrementing and decrementing it, which doesn't affect the uppermost bits as long as it doesn't grow too much.

@ibuclaw
Copy link
Member

ibuclaw commented Jul 6, 2020

Apart from small nits also mentioned by @dnadlinger, I have some reservations about whether nest and the other bool flags really are mutually exclusive (what happens if I call toChars in the middle of a gdb session after one of the flags has been set?)

They can be used concomitantly. The taken bits are the uppermost ones, whereas the only way nest can be used is by incrementing and decrementing it, which doesn't affect the uppermost bits as long as it doesn't grow too much.

Oh, now I see. I'm Captain Slow today.

@dlang-bot dlang-bot merged commit 3d11183 into dlang:master Jul 7, 2020
ghost pushed a commit to WalterBright/dmd that referenced this pull request Aug 12, 2020
Refactor `TemplateInstance` to reduce its size
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
UplinkCoder pushed a commit to UplinkCoder/dmd that referenced this pull request Aug 12, 2020
Refactor `TemplateInstance` to reduce its size
merged-on-behalf-of: Andrei Alexandrescu <andralex@users.noreply.github.com>
@UplinkCoder
Copy link
Member

This code is severely aesthetically displeasing.


extern(D) final @safe @property pure nothrow @nogc
{
ushort nest() const { return _nest & Flag.available; }
Copy link
Member

Choose a reason for hiding this comment

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

@andralex style mistake

Copy link
Member

Choose a reason for hiding this comment

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

Which one?
It's in line with https://dlang.org/dstyle.html (see "exceptions") and common pattern used all over in DMD/Druntime/Phobos.

bool semantictiargsdone() const { return (_nest & Flag.semantictiargsdone) != 0; }
void semantictiargsdone(bool x)
{
if (x) _nest |= Flag.semantictiargsdone;
Copy link
Member

Choose a reason for hiding this comment

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

@andralex style mistake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants