Skip to content

Avoid generating lots of small temporary functions.#50

Merged
pbackus merged 1 commit intopbackus:masterfrom
FeepingCreature:fix/avoid-generating-lots-of-small-functions
Nov 27, 2020
Merged

Avoid generating lots of small temporary functions.#50
pbackus merged 1 commit intopbackus:masterfrom
FeepingCreature:fix/avoid-generating-lots-of-small-functions

Conversation

@FeepingCreature
Copy link
Contributor

@FeepingCreature FeepingCreature commented Nov 27, 2020

  • Move destructor lambda into global scope (allow instance reuse)
  • Move stride template into global scope (allow instance reuse)
  • getValues yields a string of an argument list instead of a value tuple.

Effects:

  • slightly slower in normal operation
  • enormously faster in degenerate cases (large number of types, -O -inline) due to avoiding overloading the inliner
  • smaller object file size.

To reproduce the degenerate case, try with this test program (remember -O -inline):

module test;

import std;
import sumtype;

struct S(int i) { }

void main() {
    alias mega = SumType!(staticMap!(S, aliasSeqOf!(15.iota)));
    mega.init == mega.init;
}

Adjust the iota to make things slower. Note that we have a 21-type SumType in practice - this is not academic! If you set iota to 21, then in the stock 1.0.0 version the optimizer will run for at least five minutes. (At least that's where I gave up.)

@pbackus
Copy link
Owner

pbackus commented Nov 27, 2020

The changes to getValue fail when compiling with -betterC. This should have been caught automatically, but there was a typo in my Github Actions workflow (now fixed) preventing tests from being run on PRs. You can test your changes locally with test-betterc.sh.

- Move destructor lambda into global scope (allow instance reuse)
- Move `stride` template into global scope (allow instance reuse)
- `getValues` yields a string of an argument list instead of a value tuple.

Effects:

- slightly slower in normal operation
- enormously faster in degenerate cases (large number of types, `-O -inline`) due to avoiding overloading the inliner
- smaller object file size.
@FeepingCreature FeepingCreature force-pushed the fix/avoid-generating-lots-of-small-functions branch from 5dbf6cd to 88b527b Compare November 27, 2020 16:47
@FeepingCreature
Copy link
Contributor Author

The lack of format! and join really hurts, even at compiletime. Seems to work now though.

@pbackus pbackus merged commit 97fc38e into pbackus:master Nov 27, 2020
@pbackus
Copy link
Owner

pbackus commented Nov 27, 2020

Tagged as v1.0.1. Thanks a lot!

@FeepingCreature FeepingCreature deleted the fix/avoid-generating-lots-of-small-functions branch November 27, 2020 17:14
pbackus added a commit to pbackus/phobos that referenced this pull request Dec 4, 2020
Corresponds to the following sumtype commits:

- 97fc38e4ac6c18e049c90f5a7657997155af198e
- 7e6ee90e4b8bc8bdda65af8c24c945aa3577e5c6
- 2032c14b0a7d29c445700068c92e513b2ad0619c
- dc461a4c2c1644b0073c57c5d87f251cd2ecb70a
- 72b4936d92875583eeb1454d70f76f3309930e85

See pbackus/sumtype#50 for more details.
pbackus added a commit that referenced this pull request Jan 14, 2021
pbackus added a commit to pbackus/phobos that referenced this pull request Jan 27, 2021
Corresponds to the following sumtype commits:

- 97fc38e4ac6c18e049c90f5a7657997155af198e
- 7e6ee90e4b8bc8bdda65af8c24c945aa3577e5c6
- 2032c14b0a7d29c445700068c92e513b2ad0619c
- dc461a4c2c1644b0073c57c5d87f251cd2ecb70a
- 72b4936d92875583eeb1454d70f76f3309930e85

See pbackus/sumtype#50 for more details.
pbackus added a commit to pbackus/phobos that referenced this pull request Feb 20, 2021
Corresponds to the following sumtype commits:

- 97fc38e4ac6c18e049c90f5a7657997155af198e
- 7e6ee90e4b8bc8bdda65af8c24c945aa3577e5c6
- 2032c14b0a7d29c445700068c92e513b2ad0619c
- dc461a4c2c1644b0073c57c5d87f251cd2ecb70a
- 72b4936d92875583eeb1454d70f76f3309930e85

See pbackus/sumtype#50 for more details.
@pbackus
Copy link
Owner

pbackus commented Jun 7, 2021

This PR introduced a regression (#65).

pbackus added a commit that referenced this pull request Jun 7, 2021
Fixes #65 on Github, a regression introduced in 88b527b (Github PR #50)
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