Skip to content

Add -ftime-trace instrumentation for the inliner pass#22911

Merged
thewilsonator merged 2 commits intodlang:masterfrom
suyashkumar102:fix/ftime-trace-inliner
Apr 18, 2026
Merged

Add -ftime-trace instrumentation for the inliner pass#22911
thewilsonator merged 2 commits intodlang:masterfrom
suyashkumar102:fix/ftime-trace-inliner

Conversation

@suyashkumar102
Copy link
Copy Markdown
Contributor

After PR #22825 I kept looking at traces and noticed the inliner pass just
doesn't show up. When compiling with -inline -ftime-trace, the trace shows Semantic analysis followed by Code generation— nothing in between.

The frontend inliner can contribute to compile-time slowdowns in some codebases, and having visibility into its activity may help when investigating such cases. For example, #20315 highlights a situation where the inliner was suspected to play a role in increased compile times, and there was nothing in the trace to look at when diagnosing it.

This adds two new event types:

  • Inlining — top-level span covering the entire inliner pass
  • Inline: <function> — per-function span for each function scanned

The Inlining span covers both the pragma-inline scan and the full -inline scan.

  1. ftimetrace_inline.d compiled with -inline:
Screenshot 2026-04-11 200430
  1. ftimetrace_pragma.d compiled without -inline :
Screenshot 2026-04-11 200558
  1. Recursive template case (reduction from DMD frontend inliner causes major slowdown #20315) —
    spans showing the inliner working through the divide-and-conquer tree:
Screenshot 2026-04-11 200704

Updated ftimetrace.d and added ftimetrace_inline.d and ftimetrace_pragma.d
to cover all cases.

noticed the inliner pass was invisible in -ftime-trace output — was looking at a trace after dlang#22825 and realized the whole inlining phase just disappears. added inlineGeneral and per-function inline spans following the same pattern as the existing sema/parse spans. makes it possible to see which functions are taking time during inlining, useful for diagnosing compile-time issues in codebases that use -inline heavily.
@dlang-bot
Copy link
Copy Markdown
Contributor

Thanks for your pull request and interest in making D better, @suyashkumar102! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

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#22911"

@nordlow
Copy link
Copy Markdown
Contributor

nordlow commented Apr 11, 2026

Thanks for doing this. Btw, while you have your brain cache partially filled with details on inlining, would it be possible for you to investigate why -cov coverage for a function is lost when it's qualified with pragma(inline, true);?

@suyashkumar102
Copy link
Copy Markdown
Contributor Author

suyashkumar102 commented Apr 11, 2026

@nordlow Tried it out.
int square(int x) shows 0000000. Zero hits even though it's called

Screenshot 2026-04-11 233048

Seems this is Issue #18337. Good timing since I'm already deep in the inliner code.
I'll take a proper look at where the coverage data needs to be preserved during the inline expansion and see if there's a clean fix!

@nordlow
Copy link
Copy Markdown
Contributor

nordlow commented Apr 11, 2026

Seems this is Issue #18337. Good timing since I'm already deep in the inliner code. I'll take a proper look at where the coverage data needs to be preserved during the inline expansion and see if there's a clean fix!

Awesome! See also #22830.

@suyashkumar102
Copy link
Copy Markdown
Contributor Author

Awesome! See also #22830.

Got a fix working — opened PR #22922. Followed @dkorpel's suggestion from #22830.

@maxhaton maxhaton added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label Apr 18, 2026
@thewilsonator thewilsonator merged commit 724539c into dlang:master Apr 18, 2026
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merge:72h no objection -> merge The PR will be merged if there are no objections raised.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants