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

Avoid heap allocations in Htonl #55

Merged
merged 2 commits into from
Nov 25, 2024
Merged

Conversation

jinroh
Copy link
Contributor

@jinroh jinroh commented Nov 21, 2024

Avoids heap allocations when in Htonl.

rpmdb_test.go:131: Allocations per run "CentOS5 plain": from 296182 to 26664
rpmdb_test.go:131: Allocations per run "CentOS6 Plain": from 346814 to 41826
rpmdb_test.go:131: Allocations per run "CentOS6 with Development tools": from 703604 to 82604
rpmdb_test.go:131: Allocations per run "CentOS6 with many packages": from 866345 to 96344
rpmdb_test.go:131: Allocations per run "CentOS7 Plain": from 389679 to 46470
rpmdb_test.go:131: Allocations per run "CentOS7 with Development tools": from 721811 to 100046
rpmdb_test.go:131: Allocations per run "CentOS7 with many packages": from 1061689 to 127268
rpmdb_test.go:131: Allocations per run "CentOS7 with Python 3.5": from 911443 to 106971
rpmdb_test.go:131: Allocations per run "CentOS7 with httpd 2.4": from 588830 to 62563
rpmdb_test.go:131: Allocations per run "CentOS8 with modules": from 1440866 to 136506
rpmdb_test.go:131: Allocations per run "RHEL UBI8 from s390x": from 508158 to 51291
rpmdb_test.go:131: Allocations per run "SLE15 with NDB style rpm database": from 98312 to 5654
rpmdb_test.go:131: Allocations per run "Fedora35 with SQLite3 style rpm database": from 371913 to 22497
rpmdb_test.go:131: Allocations per run "Fedora35 plus MongoDB with SQLite3 style rpm database": from 382463 to 23151

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -119,6 +119,17 @@ func TestPackageList(t *testing.T) {
}
})
}

for _, tt := range tests {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this test? ListPackages is already tested above and this test doesn't seem to add any value for testing. BenchmarkXXX makes more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. Let me arrange that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 24028bb

@jinroh
Copy link
Contributor Author

jinroh commented Nov 25, 2024

Before

goos: darwin
goarch: arm64
pkg: github.com/knqyf263/go-rpmdb/pkg
cpu: Apple M1 Max
BenchmarkRpmDB_Package/CentOS5_plain-10                                       52          23991929 ns/op        49760552 B/op     296190 allocs/op
BenchmarkRpmDB_Package/CentOS6_Plain-10                                       40          28327141 ns/op        62770936 B/op     346915 allocs/op
BenchmarkRpmDB_Package/CentOS6_with_Development_tools-10                      18          60692363 ns/op        169853252 B/op    703798 allocs/op
BenchmarkRpmDB_Package/CentOS6_with_many_packages-10                          16          69095055 ns/op        190209496 B/op    866544 allocs/op
BenchmarkRpmDB_Package/CentOS7_Plain-10                                       37          31174939 ns/op        74387664 B/op     389787 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_Development_tools-10                      15          74731719 ns/op        240852056 B/op    721985 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_many_packages-10                          12          90756823 ns/op        276267332 B/op   1061907 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_Python_3.5-10                             14          79331298 ns/op        227163886 B/op    911661 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_httpd_2.4-10                              28          41661811 ns/op        97779868 B/op     588991 allocs/op
BenchmarkRpmDB_Package/CentOS8_with_modules-10                                12          91337743 ns/op        234611008 B/op   1441177 allocs/op
BenchmarkRpmDB_Package/RHEL_UBI8_from_s390x-10                                32          35893936 ns/op        94996768 B/op     508319 allocs/op
BenchmarkRpmDB_Package/SLE15_with_NDB_style_rpm_database-10                  255           4641358 ns/op         6810925 B/op      98331 allocs/op
BenchmarkRpmDB_Package/Fedora35_with_SQLite3_style_rpm_database-10                    55          20780058 ns/op        33609021 B/op     371972 allocs/op
BenchmarkRpmDB_Package/Fedora35_plus_MongoDB_with_SQLite3_style_rpm_database-10                       55          25275911 ns/op        34199078 B/op     382543 allocs/op
PASS

AFTER

goos: darwin
goarch: arm64
pkg: github.com/knqyf263/go-rpmdb/pkg
cpu: Apple M1 Max
BenchmarkRpmDB_Package/CentOS5_plain-10                                       66          18810401 ns/op        41674131 B/op      26672 allocs/op
BenchmarkRpmDB_Package/CentOS6_Plain-10                                       50          22820472 ns/op        53618285 B/op      41945 allocs/op
BenchmarkRpmDB_Package/CentOS6_with_Development_tools-10                      22          49735311 ns/op        151215652 B/op     82787 allocs/op
BenchmarkRpmDB_Package/CentOS6_with_many_packages-10                          20          55669265 ns/op        167104224 B/op     96553 allocs/op
BenchmarkRpmDB_Package/CentOS7_Plain-10                                       46          25464075 ns/op        64089220 B/op      46576 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_Development_tools-10                      18          64353773 ns/op        222201363 B/op    100239 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_many_packages-10                          15          74720281 ns/op        248222750 B/op    127488 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_Python_3.5-10                             16          65440023 ns/op        203025041 B/op    107189 allocs/op
BenchmarkRpmDB_Package/CentOS7_with_httpd_2.4-10                              34          32086971 ns/op        81990270 B/op      62729 allocs/op
BenchmarkRpmDB_Package/CentOS8_with_modules-10                                18          67958331 ns/op        195470964 B/op    136830 allocs/op
BenchmarkRpmDB_Package/RHEL_UBI8_from_s390x-10                                40          28148409 ns/op        81290482 B/op      51460 allocs/op
BenchmarkRpmDB_Package/SLE15_with_NDB_style_rpm_database-10                  453           2649647 ns/op         4029938 B/op       5671 allocs/op
BenchmarkRpmDB_Package/Fedora35_with_SQLite3_style_rpm_database-10                    76          13913482 ns/op        23125151 B/op      22573 allocs/op
BenchmarkRpmDB_Package/Fedora35_plus_MongoDB_with_SQLite3_style_rpm_database-10                       90          13983450 ns/op        23415763 B/op      23217 allocs/op
PASS

@knqyf263
Copy link
Owner

Thanks

@knqyf263 knqyf263 merged commit 7670f0f into knqyf263:master Nov 25, 2024
3 checks passed
@jinroh jinroh deleted the jinroh/allocs branch November 26, 2024 07:46
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

Successfully merging this pull request may close these issues.

2 participants