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

sumtype: reduce template overhead of match #9087

Merged
merged 5 commits into from
Nov 21, 2024

Conversation

pbackus
Copy link
Contributor

@pbackus pbackus commented Nov 20, 2024

Please review this PR commit-by-commit.

The changes in this PR can be grouped into two categories:

  1. Refactoring of helper templates use by matchImpl to eliminate unnecessary instantiations.
  2. Addition of a fast path for single dispatch to matchImpl.

Altogether, these changes reduce the time take to run std.sumtype's test suite by about 14%.

See also pbackus/sumtype#91, which added these changes to the dub version of sumtype.

Before

Command Mean [s] Min [s] Max [s]
../dmd/generated/linux/release/64/dmd -conf= -I../dmd/druntime/import -w -preview=dip1000 -preview=dtorfields -preview=fieldwise -m64 -fPIC -O -release -main -unittest -version=StdUnittest generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-lpthread -L-lm -L-ldl -cov=ctfe -run std/sumtype.d 4.790 ± 0.234 4.586 5.198

After

Command Mean [s] Min [s] Max [s]
../dmd/generated/linux/release/64/dmd -conf= -I../dmd/druntime/import -w -preview=dip1000 -preview=dtorfields -preview=fieldwise -m64 -fPIC -O -release -main -unittest -version=StdUnittest generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-lpthread -L-lm -L-ldl -cov=ctfe -run std/sumtype.d 4.143 ± 0.079 4.064 4.290

Tuples with the same dimensions now share a single instantiation,
regardless of the types held by the SumTypes they are used for.
Calls to matchImpl whose SumType arguments have the same dimensions will
now share instantiations, instead of having separate ones.
This reduces the number of templates instantiated by matchImpl in the
common case where only one SumType is being matched on.
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @pbackus! 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 + phobos#9087"

@pbackus pbackus merged commit 08638dd into dlang:master Nov 21, 2024
9 checks passed
@pbackus pbackus deleted the sumtype-template-overhead branch November 21, 2024 01:39
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