summaryrefslogtreecommitdiff
path: root/internal/processing/stream/authorize_test.go
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-07-09 01:38:33 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-07-09 01:38:33 +0200
commitc8a4ce9a88fbe3122d796641406016ae4e83213d (patch)
tree20ad376fd77cf3c9fbec0f58d35356fb03a46bf5 /internal/processing/stream/authorize_test.go
parent[chore] update error message (#4311) (diff)
downloadgotosocial-c8a4ce9a88fbe3122d796641406016ae4e83213d.tar.xz
[performance] use our own typed value context types for Value() key checking to improve performance (#4316)
Replaces our gtscontext package context.Context handling with our own typed contexts instead of `context.WithValue()`. I wrote a quick benchmark consisting of (printlns to stop the compiler optimizing instructions away): ```golang func BenchmarkContexts(b *testing.B) { var receiving *gtsmodel.Account var requesting *gtsmodel.Account var otherIRIs []*url.URL b.RunParallel(func(pb *testing.PB) { for pb.Next() { ctx := context.Background() ctx = gtscontext.SetBarebones(ctx) ctx = gtscontext.SetFastFail(ctx) ctx = gtscontext.SetDryRun(ctx) ctx = gtscontext.SetReceivingAccount(ctx, receiving) ctx = gtscontext.SetRequestingAccount(ctx, requesting) ctx = gtscontext.SetOtherIRIs(ctx, otherIRIs) if !gtscontext.Barebones(ctx) { println("oh no!") } if !gtscontext.IsFastfail(ctx) { println("oh no!") } if !gtscontext.DryRun(ctx) { println("oh no!") } if gtscontext.ReceivingAccount(ctx) != nil { println("oh no!") } if gtscontext.RequestingAccount(ctx) != nil { println("oh no!") } if len(gtscontext.OtherIRIs(ctx)) > 0 { println("oh no!") } } }) } ``` Before results: ```shell kim @ ~/Projects/main/gts.4 --> go test -v -run=none -bench=.* -benchmem ./internal/gtscontext/ -count=5 goos: linux goarch: amd64 pkg: code.superseriousbusiness.org/gotosocial/internal/gtscontext cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics BenchmarkContexts BenchmarkContexts-16 19050348 61.73 ns/op 288 B/op 6 allocs/op BenchmarkContexts-16 18245772 61.71 ns/op 288 B/op 6 allocs/op BenchmarkContexts-16 18853680 61.80 ns/op 288 B/op 6 allocs/op BenchmarkContexts-16 18561621 62.67 ns/op 288 B/op 6 allocs/op BenchmarkContexts-16 17819241 62.89 ns/op 288 B/op 6 allocs/op PASS ok code.superseriousbusiness.org/gotosocial/internal/gtscontext 6.112s ``` After results: ```shell kim @ ~/Projects/main/gts.4 --> go test -v -run=none -bench=.* -benchmem ./internal/gtscontext/ -count=5 goos: linux goarch: amd64 pkg: code.superseriousbusiness.org/gotosocial/internal/gtscontext cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics BenchmarkContexts BenchmarkContexts-16 28038618 41.67 ns/op 144 B/op 6 allocs/op BenchmarkContexts-16 26537552 42.50 ns/op 144 B/op 6 allocs/op BenchmarkContexts-16 26720542 42.39 ns/op 144 B/op 6 allocs/op BenchmarkContexts-16 27408031 43.15 ns/op 144 B/op 6 allocs/op BenchmarkContexts-16 25597026 44.02 ns/op 144 B/op 6 allocs/op PASS ok code.superseriousbusiness.org/gotosocial/internal/gtscontext 5.997s ``` Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4316 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/processing/stream/authorize_test.go')
0 files changed, 0 insertions, 0 deletions