-
Notifications
You must be signed in to change notification settings - Fork 76
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
clang warning on exit-time declaration #13
Comments
I'm not sure that this warning is really a problem. It's probably better to ignore it. |
@r-lyeh Was that really a fix though? This is a "run-time" vs "on-exit" performance decision, and in my experience most people would gladly accept the trade-off. After the "fix", at a first glance the performance seems atrocious, a single call of uuid::base62():
So for example, the base62() method will allocate the string 3 times where just a reference to the static std::string would have been enough. In applications where objects and their uuid's need to be serialized, this looks unacceptable. |
Have anyone measured/benchmarked both implementations before blaming at the fix? :) I guess the performance is similar in both cases: it was 1 global string access + 3 string allocs before, and it is a local access (to a likely inlined variable) + 3 string allocs now. But then again, it would need some benchmarking before taking any further decision. It could be better if I would have done a |
Months ago I did do some benchmarks to improve performance in our application. UUID creation was the slowest part, the optimisations I suggested above seemed to help improve it, at least in my benchmarks. |
Quickly benchmarking calls to base62() revealed a 10~15% performance difference on my computer. Locally allocated results Cached std::string results |
Uuuh, what? I have a feeling we are not talking about the same thing.
If before we were accessing a global std::string instance and feeding it to the rebase, no casts were being required and thus removing the need for unnecessary string allocations. |
Just found something else inside rebase, Results: Another ~15% on top of the previous benchmark (with the cached std::string). |
Great find @Edensan. I might have to do that quick edit for our app. |
Super. I 'll have a commit to this fix asap, unless somebody else is faster at PRs :) |
@Edensan can you benchmark that branch please? I'm curious to see the results! |
Benchmarking... 1902357 base62/sec Woah, almost more than 6x performance improvement for the base62() apparently, that's what I call an optimization 👍 |
My guess is that re-allocating strings in that loop was just killing the performance, I see you're using a char buffer now and doing a single std::string allocation, good. |
What an increase! Nice work @r-lyeh |
I wonder if base62 remains 100% intact and thus is backward compatible. I am 98% sure it is safe to use. It would be great if any of you guys mind to apply the branch and test your unit-test suites with it :) |
@r-lyeh Got a warning that this line is not being used.
But all my tests run fine. Performance is looking good. Time to merge the changes into master after fixing this warning? |
hey @zammbi, I just checked and the base62optim branch wont pass tests. Gotta review the rebuild(b62) method and let you know then |
Merged |
This code at around line 367:
inline std::string uuid::base62() const {
static const std::string base62 =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
return rebase( ab, base62 ) + "-" + rebase( cd, base62 );
}
and this code at around line 737:
static const std::string base62 =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
shows clang warning as below:
The IDE I used is "Xcode Version 7.3.1"
The text was updated successfully, but these errors were encountered: