Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: make debug a constant set using a build flag (gnolang#2072)
Changing the `debug` flag from a variable to a constant results in increased performance anywhere in the code where the `if debug {` conditional exists. The setting of the debug flag is now facilitated by a `debug` build tag. Here are a few benchmarks showing the performance difference for TypedValue Set and Get operations. The benchmarks suffixed with 'New' are those run with debugging disabled after introducing the build tag. The other benchmarks were run with debugging disabled before introducing the build tag. ``` go test -cpu 1,2,4,8 -benchmem -bench '^BenchmarkTV' -run=^$ goos: darwin goarch: amd64 pkg: github.com/gnolang/gno/gnovm/pkg/gnolang cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz BenchmarkTVGetBool 616270255 1.919 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBool-2 623206738 1.859 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBool-4 645019149 1.825 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBool-8 628096153 1.897 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBoolNew 1000000000 0.3015 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBoolNew-2 1000000000 0.2997 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBoolNew-4 1000000000 0.3026 ns/op 0 B/op 0 allocs/op BenchmarkTVGetBoolNew-8 1000000000 0.3009 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBool 636429537 1.895 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBool-2 612271684 1.983 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBool-4 583097722 1.923 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBool-8 608042474 1.949 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBoolNew 1000000000 0.3109 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBoolNew-2 1000000000 0.3116 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBoolNew-4 1000000000 0.3101 ns/op 0 B/op 0 allocs/op BenchmarkTVSetBoolNew-8 1000000000 0.3080 ns/op 0 B/op 0 allocs/op BenchmarkTVGetInt 596222908 1.979 ns/op 0 B/op 0 allocs/op BenchmarkTVGetInt-2 565257805 2.024 ns/op 0 B/op 0 allocs/op BenchmarkTVGetInt-4 603462258 1.913 ns/op 0 B/op 0 allocs/op BenchmarkTVGetInt-8 623668717 1.896 ns/op 0 B/op 0 allocs/op BenchmarkTVGetIntNew 1000000000 0.3049 ns/op 0 B/op 0 allocs/op BenchmarkTVGetIntNew-2 1000000000 0.3035 ns/op 0 B/op 0 allocs/op BenchmarkTVGetIntNew-4 1000000000 0.3139 ns/op 0 B/op 0 allocs/op BenchmarkTVGetIntNew-8 1000000000 0.3006 ns/op 0 B/op 0 allocs/op BenchmarkTVSetInt 646375224 1.819 ns/op 0 B/op 0 allocs/op BenchmarkTVSetInt-2 639805758 1.817 ns/op 0 B/op 0 allocs/op BenchmarkTVSetInt-4 641337288 1.840 ns/op 0 B/op 0 allocs/op BenchmarkTVSetInt-8 636959119 1.836 ns/op 0 B/op 0 allocs/op BenchmarkTVSetIntNew 1000000000 0.3011 ns/op 0 B/op 0 allocs/op BenchmarkTVSetIntNew-2 1000000000 0.3017 ns/op 0 B/op 0 allocs/op BenchmarkTVSetIntNew-4 1000000000 0.2984 ns/op 0 B/op 0 allocs/op BenchmarkTVSetIntNew-8 1000000000 0.2909 ns/op 0 B/op 0 allocs/op ``` <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [x] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details>
- Loading branch information