ast: Optimize set/object lookups and Number comparison.
Lookups for sets and objects use their own type specific equality checks instead of relying on the general purpose Compare. This improves the performance about 25%. The duplication of code is unavoidable to avoid the allocations, unfortunately. Number comparison is now allocation free for integers. This because Int64() of json.Number uses allocation free strconv.ParseInt internally. This shows up in the additional 60% improvement of set membership benchmarks as they use integer keys. Most notable improvements in benchmarks: benchmark old ns/op new ns/op delta BenchmarkObjectLookup/5-8 37.3 31.9 -14.48% BenchmarkObjectLookup/50-8 44.7 39.7 -11.19% BenchmarkObjectLookup/500-8 46.6 41.7 -10.52% BenchmarkObjectLookup/5000-8 43.6 38.4 -11.93% BenchmarkSetIntersection/5-8 2309 928 -59.81% BenchmarkSetIntersection/50-8 24562 9121 -62.87% BenchmarkSetIntersection/500-8 260022 93373 -64.09% BenchmarkSetIntersection/5000-8 2796645 1035045 -62.99% BenchmarkSetIntersectionDifferentSize/4-8 1774 781 -55.98% BenchmarkSetIntersectionDifferentSize/50-8 1847 875 -52.63% BenchmarkSetIntersectionDifferentSize/500-8 1849 864 -53.27% BenchmarkSetIntersectionDifferentSize/5000-8 1884 890 -52.76% BenchmarkSetMembership/5-8 339 55.1 -83.75% BenchmarkSetMembership/50-8 383 65.3 -82.95% BenchmarkSetMembership/500-8 403 70.5 -82.51% BenchmarkSetMembership/5000-8 418 75.1 -82.03% BenchmarkConcurrency1-8 219100992 218699478 -0.18% BenchmarkConcurrency2-8 121519274 119096088 -1.99% BenchmarkConcurrency4-8 88765327 78934589 -11.07% BenchmarkConcurrency8-8 93624724 82432804 -11.95% BenchmarkConcurrency4Readers1Writer-8 90931759 80533879 -11.43% BenchmarkConcurrency8Writers-8 237043373 233709595 -1.41% Signed-off-by: Teemu Koponen <koponen@styra.com>
T
Teemu Koponen committed
af970b7ef645c77f07f26501cb596183dabed3d1
Parent: 762e9ad
Committed by Patrick East <east.patrick@gmail.com>
on 8/28/2019, 12:16:36 AM