Skip to content

Fix Issue 15110 - pragma(inline, true) should always *attempt* to inline regardless of the -inline compiler flag - #9978

Closed
JinShil wants to merge 1 commit into
dlang:masterfrom
JinShil:fix_15110
Closed

JinShil wants to merge 1 commit into
dlang:masterfrom
JinShil:fix_15110

Conversation

@JinShil

@JinShil JinShil commented Jun 5, 2019 •

Copy link
Copy Markdown
Contributor

Currently the compiler does not attempt to do any inlining whatsoever regardless of any pragma(inline, true) annotations. It will only attempt to inline functions if the compiler is invoked with the -inline flag.

This PR changes the behavior of pragma(inline, true) so the compiler always attempts to inline a function annotated with pragma(inline, true) regardless of whether or not the compiler is invoked with the -inline` flag. All other behaviors remain the same.

@thewilsonator

Copy link
Copy Markdown
Contributor

A little more description would be useful...

Also cc @TurkeyMan

@JinShil

JinShil commented Jun 5, 2019

Copy link
Copy Markdown
Contributor Author

Requires dlang/phobos#7059

@JinShil JinShil changed the title Fix Issue 15110 - pragma(inline) rarely works how I want it to Fix Issue 15110 - pragma(inline, true) should always *attempt* and inline regardless of the -inline compiler flag Jun 5, 2019
@JinShil JinShil changed the title Fix Issue 15110 - pragma(inline, true) should always *attempt* and inline regardless of the -inline compiler flag Fix Issue 15110 - pragma(inline, true) should always *attempt* to inline regardless of the -inline compiler flag Jun 5, 2019
@thewilsonator

Copy link
Copy Markdown
Contributor

see also #7690 (Still haven't been able to figure out why that one fails on Ocean yet).

@WalterBright WalterBright left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The reason this is not done is because always doing an inline scan slows down the compiler.

@WalterBright

Copy link
Copy Markdown
Member

Doing this in away that doesn't always require an inline scan is a much more difficult fix than this is.

@JinShil

JinShil commented Jun 5, 2019 •

Copy link
Copy Markdown
Contributor Author

The reason this is not done is because always doing an inline scan slows down the compiler.

This claim does make sense, but I'm not seeing any significant difference. There are other things in a build that contribute much more to the time than this.

Here's my data compiling Phobos:

With this PR:

time make -f posix.mak

# Take 1
real	0m33.876s
user	0m31.966s
sys	0m1.602s

# Take 2
real	0m40.413s
user	0m38.207s
sys	0m1.830s

Without this PR:

time make -f posix.mak

# Take 1
real	0m47.470s
user	0m44.997s
sys	0m2.032s

# Take 2
real	0m33.681s
user	0m31.786s
sys	0m1.587s

Also most of the inline scanning is gated here

dmd/src/dmd/inline.d

Lines 1691 to 1694 in e9ef759

if (fd.inlining == PINLINE.default_ && !global.params.useInline)
{
return false;
}
which probably explains the insignificant change in compile times. That gate means only those functions attributed with pragma(inline, true) are subject to the full scan.

Doing this in away that doesn't always require an inline scan is a much more difficult fix than this is.

Then I suggest merging this and adding a bug report to implement the more difficult fix as an improvement.

@WalterBright

Copy link
Copy Markdown
Member
  1. The way you're doing timings is not accurate enough.

  2. "insignificant" costs have a way of adding up. DMD has been steadily slowing down with all these insignificant costs. Not only does it have to do the scanning, it has to do semantic analysis of every function called - a task it currently skips.

Then I suggest merging this and adding a bug report to implement the more difficult fix as an improvement.

No, because the bug is not that significant in that its effect is minor, but this PR negatively affects everyone. There are too many higher priority things I need to work on.

@JinShil

JinShil commented Jun 5, 2019 •

Copy link
Copy Markdown
Contributor Author

Here are timings for just the compiling stage of the phobos build:

Without this PR:

real	0m15.303s
user	0m14.152s
sys	0m0.848s

With this PR:

real	0m15.461s
user	0m14.332s
sys	0m0.855s

@JinShil

JinShil commented Jun 5, 2019

Copy link
Copy Markdown
Contributor Author

No, because the bug is not that significant in that its effect is minor, but this PR negatively affects everyone.

It doesn't look like it negatively affects anyone, and would positively affect a few people including myself.

@WalterBright

Copy link
Copy Markdown
Member

A 1% slowdown is significant.

@JinShil

JinShil commented Jun 6, 2019 •

Copy link
Copy Markdown
Contributor Author

Would you be willing to advise me with any specifics to improve this PR to your satisfaction?

@WalterBright

Copy link
Copy Markdown
Member

I don't really know of a good way to do it that isn't slow, or I'd have done it already.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants