TheThingsIndustries / protoc-gen-fieldmask

Generate field mask utilities from proto files
Apache License 2.0
10 stars 3 forks source link

add benchmark and improve performance #36

Closed sysulq closed 4 years ago

sysulq commented 4 years ago

Summary

Performance need improvement.

Changes

Notes for Reviewers

benchmark before

Running tool: /usr/local/opt/go/libexec/bin/go test -benchmem -run=^$ github.com/TheThingsIndustries/protoc-gen-fieldmask -bench ^(BenchmarkSetFields)$

goos: darwin
goarch: amd64
pkg: github.com/TheThingsIndustries/protoc-gen-fieldmask
BenchmarkSetFields/nil_source-4               436851          3307 ns/op        1840 B/op         20 allocs/op
BenchmarkSetFields/no_paths-4                7820179           184 ns/op          48 B/op          1 allocs/op
BenchmarkSetFields/a.b-4                      690620          1959 ns/op        1136 B/op         12 allocs/op
BenchmarkSetFields/a.b,a.a.a,a.b,a.b,b,testOneof-4            349719          3961 ns/op        1584 B/op         19 allocs/op
BenchmarkSetFields/destination_testOneof_mismatch-4           544834          2126 ns/op        1216 B/op         13 allocs/op
BenchmarkSetFields/source_testOneof_mismatch-4                569792          2531 ns/op        1200 B/op         13 allocs/op
BenchmarkSetFields/unset_testOneof-4                          693373          1856 ns/op        1120 B/op         11 allocs/op
BenchmarkSetFields/set_non-existing_testOneof-4               718399          1932 ns/op        1120 B/op         11 allocs/op
BenchmarkSetFields/testOneof.k.a.a-4                          310720          4273 ns/op        2496 B/op         27 allocs/op
BenchmarkSetFields/non-nullable_c.a-4                         559153          2054 ns/op        1136 B/op         12 allocs/op
BenchmarkSetFields/non-existent_top-level_field-4             795229          1372 ns/op         512 B/op          7 allocs/op
BenchmarkSetFields/non-existent_sub-field-4                   666229          1767 ns/op         752 B/op         11 allocs/op
BenchmarkSetFields/non-existent_oneof-4                       622804          2440 ns/op        1216 B/op         15 allocs/op
BenchmarkSetFields/double_oneofs-4                            472322          3343 ns/op        1280 B/op         15 allocs/op
PASS
ok      github.com/TheThingsIndustries/protoc-gen-fieldmask 21.144s
Success: Benchmarks passed.

benchmark after

Running tool: /usr/local/opt/go/libexec/bin/go test -benchmem -run=^$ github.com/TheThingsIndustries/protoc-gen-fieldmask -bench ^(BenchmarkSetFields)$

goos: darwin
goarch: amd64
pkg: github.com/TheThingsIndustries/protoc-gen-fieldmask
BenchmarkSetFields/nil_source-4               634264          1922 ns/op        1360 B/op         13 allocs/op
BenchmarkSetFields/no_paths-4               70568052            17.7 ns/op         0 B/op          0 allocs/op
BenchmarkSetFields/a.b-4                     1000000          1098 ns/op         880 B/op          8 allocs/op
BenchmarkSetFields/a.b,a.a.a,a.b,a.b,b,testOneof-4            554421          2980 ns/op        1248 B/op         15 allocs/op
BenchmarkSetFields/destination_testOneof_mismatch-4          1000000          1359 ns/op         960 B/op          9 allocs/op
BenchmarkSetFields/source_testOneof_mismatch-4                828547          1309 ns/op         944 B/op          9 allocs/op
BenchmarkSetFields/unset_testOneof-4                         1000000          1004 ns/op         864 B/op          7 allocs/op
BenchmarkSetFields/set_non-existing_testOneof-4              1000000          1028 ns/op         864 B/op          7 allocs/op
BenchmarkSetFields/testOneof.k.a.a-4                          557286          2808 ns/op        1792 B/op         17 allocs/op
BenchmarkSetFields/non-nullable_c.a-4                        1000000          1186 ns/op         880 B/op          8 allocs/op
BenchmarkSetFields/non-existent_top-level_field-4            1696417           769 ns/op         480 B/op          6 allocs/op
BenchmarkSetFields/non-existent_sub-field-4                  1000000          1167 ns/op         528 B/op          8 allocs/op
BenchmarkSetFields/non-existent_oneof-4                       892474          1960 ns/op         960 B/op         11 allocs/op
BenchmarkSetFields/double_oneofs-4                            738782          1792 ns/op        1040 B/op         12 allocs/op
PASS
ok      github.com/TheThingsIndustries/protoc-gen-fieldmask 19.506s
Success: Benchmarks passed.

Release Notes

sysulq commented 4 years ago

I think we should just keep simple logic, and no duplicated path should be guaranteed by the caller.

rvolosatovs commented 4 years ago

I agree with this change given https://github.com/TheThingsIndustries/protoc-gen-fieldmask/pull/36#discussion_r380774100 is fixed.

rvolosatovs commented 4 years ago

Merged in https://github.com/TheThingsIndustries/protoc-gen-fieldmask/commit/321adaa1af73437df4fd792e1c58358714e1ddfb