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

perf: make debug a constant set using a build flag #2072

Merged
merged 2 commits into from
May 29, 2024

Conversation

deelawn
Copy link
Contributor

@deelawn deelawn commented May 10, 2024

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
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label May 10, 2024
@deelawn deelawn requested a review from thehowl May 10, 2024 17:16
Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 54.96%. Comparing base (a03eeb3) to head (a6bc9ad).

Files Patch % Lines
gnovm/pkg/gnolang/debug.go 0.00% 6 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2072   +/-   ##
=======================================
  Coverage   54.96%   54.96%           
=======================================
  Files         481      481           
  Lines       67407    67406    -1     
=======================================
+ Hits        37049    37051    +2     
+ Misses      27337    27336    -1     
+ Partials     3021     3019    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@deelawn deelawn merged commit 98bd124 into gnolang:master May 29, 2024
13 checks passed
@deelawn deelawn deleted the perf/debug-build-flag branch May 29, 2024 21:25
omarsy pushed a commit to TERITORI/gno that referenced this pull request Jun 3, 2024
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants