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

Improve runtime performance - lazy stringification, more inlining, no statics on the hot path, move semantics for classes such as doctest::String which are used by value, etc. #69

Closed
onqtam opened this issue May 8, 2017 · 1 comment

Comments

@onqtam
Copy link
Member

onqtam commented May 8, 2017

No description provided.

onqtam added a commit that referenced this issue May 8, 2017
… don't fail - stringifying the expressions only if needed - relates #69

- also reduced a bit the size of the header with around 2kb... :D
onqtam added a commit that referenced this issue May 8, 2017
…tic local

- fixed the unary false asserts - they got broken in the previous commit...
- relates #69
onqtam added a commit that referenced this issue May 9, 2017
…translating exceptions - but that should be the exceptional path) - relates #69
onqtam added a commit that referenced this issue May 9, 2017
The only thing left to optimize for the release of 1.2 is... the String class :)
onqtam added a commit that referenced this issue May 9, 2017
- will add the final info on the runtime improvements in issue #69 but from what it seems this was a huge optimization :D - 0 allocations for the hot path when asserts dont fail.
onqtam added a commit that referenced this issue May 9, 2017
…time performance boost for an assert that doesn't fail (evaluated 10 million times inside of a loop) - relates #69
@onqtam
Copy link
Member Author

onqtam commented May 10, 2017

The following code:

TEST_CASE("") {
    for(int i = 0; i < 10000000; ++i)
        CHECK(i == i);
}

used to run for 9.0 seconds built with MinGW-w64 g++ 7.1 in Release.

Now it runs for 0.27 seconds.

There were 3 changes that I introduced:

  • A new implementation of the String class - now with a small buffer optimization - sizeof(String) is 24 and it can hold strings of length up to 23 characters (24 with the null terminator) in itself!
    The trick used for this maximum length on the stack is explained in this cppcon talk about how fbstring (from facebook/folly) is implemented.
    This got down the runtime to 4.1 seconds for that piece of code
  • Made the asserts to stringify the expressions lazily - only if they fail.
    This got down the runtime to 0.275 seconds for that code.
  • Reworked the access to the current context state to access a global instead of a local static - tiny improvement - perhaps 2-3%
    ~0.27 after this optimization

So this all amounts to a x33 faster runtime execution of asserts!

There are >> 0 << allocations while looping the assert.

All asserts benefit from these optimizations including the binary ones and the fast ones (they are the fastest not only for compile times but also for runtime) - they might not be 33 times faster but will still be a lot faster than before.

Results are similar with other compilers - will update the benchmark part of the documentation soon.

onqtam added a commit that referenced this issue May 15, 2017
… don't fail - stringifying the expressions only if needed - relates #69

- also reduced a bit the size of the header with around 2kb... :D
onqtam added a commit that referenced this issue May 15, 2017
…tic local

- fixed the unary false asserts - they got broken in the previous commit...
- relates #69
onqtam added a commit that referenced this issue May 15, 2017
…translating exceptions - but that should be the exceptional path) - relates #69
onqtam added a commit that referenced this issue May 15, 2017
The only thing left to optimize for the release of 1.2 is... the String class :)
@onqtam onqtam closed this as completed in 82c0e5c May 15, 2017
onqtam added a commit that referenced this issue May 15, 2017
…time performance boost for an assert that doesn't fail (evaluated 10 million times inside of a loop) - relates #69
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

No branches or pull requests

1 participant