Skip to content

Conversation

@pbackus
Copy link
Owner

@pbackus pbackus commented Nov 20, 2024

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

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

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

Performance data, from my personal laptop:

Before

Command Mean [s] Min [s] Max [s] Relative
dmd -unittest -main -run src/sumtype.d 1.545 ± 0.056 1.492 1.673 1.00

With refactoring

Command Mean [s] Min [s] Max [s] Relative
dmd -unittest -main -run src/sumtype.d 1.387 ± 0.058 1.342 1.530 1.00

With refactoring and fast path

Command Mean [s] Min [s] Max [s] Relative
dmd -unittest -main -run src/sumtype.d 1.329 ± 0.062 1.274 1.476 1.00

Tuples with the same dimensions now share a single instantiation,
regardless of the types held by the SumTypes they are used for.
Now they're all in the same place.
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.
@pbackus pbackus merged commit ac1f24f into master Nov 20, 2024
10 checks passed
@pbackus pbackus deleted the reduce-match-overhead branch November 20, 2024 19:09
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.

2 participants