]> git.maquefel.me Git - brevno-suite/hugo/commit
hreflect: Cache reflect method lookups used in collections.Where and others
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 26 Oct 2025 16:45:57 +0000 (17:45 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 27 Oct 2025 14:45:50 +0000 (15:45 +0100)
commite9bda21ce9d1ab80377044d8de1d7884142bfa14
tree1a1dd4e77c9e47ca9fbcd78c66e2f3aba04f7993
parent3893e70510af80e6ef9fff46c1922404706b1c2b
hreflect: Cache reflect method lookups used in collections.Where and others

We already cached the method index on the struct, but caching the resolved `reflect.Method` itself saves us from having to do another lookup on each call, which is escpeciall import in the hot path used by collections.Where and otherrs:

```bash
                                        │ master.bench │    fix-reflectmethodcache.bench     │
                                        │    sec/op    │    sec/op     vs base               │
WhereSliceOfStructPointersWithMethod-10   592.2µ ± ∞ ¹   390.1µ ± ∞ ¹  -34.14% (p=0.029 n=4)
¹ need >= 6 samples for confidence interval at level 0.95

                                        │  master.bench  │     fix-reflectmethodcache.bench     │
                                        │      B/op      │     B/op       vs base               │
WhereSliceOfStructPointersWithMethod-10   205.14Ki ± ∞ ¹   64.52Ki ± ∞ ¹  -68.55% (p=0.029 n=4)
¹ need >= 6 samples for confidence interval at level 0.95

                                        │ master.bench │    fix-reflectmethodcache.bench     │
                                        │  allocs/op   │  allocs/op    vs base               │
WhereSliceOfStructPointersWithMethod-10   9.003k ± ∞ ¹   4.503k ± ∞ ¹  -49.98% (p=0.029 n=4)
````
common/hreflect/helpers.go
common/hreflect/helpers_test.go
langs/i18n/i18n.go
tpl/collections/where.go