-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Latest Viper doubles Hugo build time #249
Comments
Here is the current benchmark effect of that commit:
That benchmark is as simple as it gets: https://github.com/spf13/viper/blob/master/viper_test.go#L957 1001 ns is too much for a map lookup. |
Sorry about that... Though I must admit I didn't try to measure it before, I'm not surprised that the new code for On my computer, the performance loss is not that huge, it is around +25%: # old
> go test -bench . -benchtime 10s -cpu 1,4 github.com/spf13/viper
BenchmarkGetBool 3000000 4243 ns/op
BenchmarkGetBool-4 3000000 5292 ns/op
# new
> go test -bench . -benchtime 10s -cpu 1,4 github.com/spf13/viper
BenchmarkGetBool 3000000 5279 ns/op
BenchmarkGetBool-4 2000000 6767 ns/op However, depth-1 keys (without ".") should be dealt with as efficiently as before, since there are no recursive calls for them (reason why I don't think a specific “fast path” would be necessary). I'll investigate why this is not the case. As for more “complex” keys, complexity should be linear in terms of key depth. On the other hand, the |
With those numbers (5k ns/op), your computer isn't representative for the PCs in the wild. And it doesn't really matter. The All* funcs doesn't matter. The common case of I believe other people than me have been "bitten" by this, so this should be fixed sooner rather than later. @benoitmasson Could you create a patch? |
I agree that this is undesirable, but I also think that proper semantics of nested maps takes precedence over performance. Viper is rarely the bottleneck for applications. Let's see if @benoitmasson can come up with some optimizations. |
Let us have a discussion about that next time. We do vendor the dependencies in Hugo, but we only commit the vendor file -- so people not using the release and just doing something similar to If I don't see a proper fix for this today I'm going to revert the commit in question, and reopen the PR so we can do a proper code review. |
Today I won't have time for that, but I can have a look tomorrow evening if that's still OK. |
I'll see if I can fix it myself. |
``` benchmark old ns/op new ns/op delta BenchmarkGetBool-4 1021 479 -53.09% BenchmarkGetBoolFromMap-4 6.56 6.39 -2.59% benchmark old allocs new allocs delta BenchmarkGetBool-4 6 4 -33.33% BenchmarkGetBoolFromMap-4 0 0 +0.00% benchmark old bytes new bytes delta BenchmarkGetBool-4 113 49 -56.64% BenchmarkGetBoolFromMap-4 0 0 +0.00% ``` Fixes spf13#249 Fixes gohugoio/hugo#2536
``` BenchmarkGetBool-4 1021 481 -52.89% BenchmarkGet-4 879 403 -54.15% BenchmarkGetBoolFromMap-4 6.56 6.40 -2.44% benchmark old allocs new allocs delta BenchmarkGetBool-4 6 4 -33.33% BenchmarkGet-4 6 4 -33.33% BenchmarkGetBoolFromMap-4 0 0 +0.00% benchmark old bytes new bytes delta BenchmarkGetBool-4 113 49 -56.64% BenchmarkGet-4 112 48 -57.14% BenchmarkGetBoolFromMap-4 0 0 +0.00% ``` Fixes spf13#249 Fixes gohugoio/hugo#2536
``` BenchmarkGetBool-4 1021 481 -52.89% BenchmarkGet-4 879 403 -54.15% BenchmarkGetBoolFromMap-4 6.56 6.40 -2.44% benchmark old allocs new allocs delta BenchmarkGetBool-4 6 4 -33.33% BenchmarkGet-4 6 4 -33.33% BenchmarkGetBoolFromMap-4 0 0 +0.00% benchmark old bytes new bytes delta BenchmarkGetBool-4 113 49 -56.64% BenchmarkGet-4 112 48 -57.14% BenchmarkGetBoolFromMap-4 0 0 +0.00% ``` Fixes #249 Fixes gohugoio/hugo#2536
Thank you @bep - however in regards to your comment, if you vendor dependencies in Hugo, the easier course of action would have been to stay on a previous version of Viper until the issue is fixed, no? |
No. I think I have explained above. |
... in general I wouldn't care too much about this, but the timing of this regression was incredibly bad for Hugo. |
I understand your frustration, but the reason to vendor is exactly to avoid this kind of regression, isn't it? |
Hugo has taken a litle half-assed approach to vendoring just to test it out. This would not have been a problem if we didn't put the |
The big problem was that the current approach to dependencies isn't really True vendoring would resolve this but it would also bring a lot of
|
Candidate commit:
ec4eb2f
We are in the process of removing viper.Get* invocations in Hugo hot paths, but I consider this to be a regression bug that should be fixed.
We should also add some benchmarks for the most common functionality so we can spot this earlier.
See gohugoio/hugo#2536
The text was updated successfully, but these errors were encountered: