mirror of
https://github.com/temporalio/temporal.git
synced 2026-08-30 18:41:49 -07:00
## What changed? I replaced the outstandingTasks map with an ordered treemap and optimized completeTask to only scan what was necessary to update the ack level. ## Why? The old implementation of completeTask required a full scan of the task map in order to move the ack level which had terrible performance. By storing tasks in an ordered set we can limit the scan's size by stopping at the first unacked task. This trades addTask performance for completeTask performance but since all added tasks are presumably completed we should be fine with 1/3 the performance on addTask for 227x the completeTask performance. With this change both operations run in about the same amount of time. Before: ``` $ go test -bench=AckManager ./service/matching/... -run=FooBarBaz goos: darwin goarch: arm64 pkg: go.temporal.io/server/service/matching BenchmarkAckManager_AddTask-12 22768 52206 ns/op BenchmarkAckManager_CompleteTask-12 38 29293019 ns/op ``` After: ``` $ go test -bench=AckManager ./service/matching -run=FooBarBaz goos: darwin goarch: arm64 pkg: go.temporal.io/server/service/matching BenchmarkAckManager_AddTask-12 8127 147226 ns/op BenchmarkAckManager_CompleteTask-12 8626 136614 ns/op ``` ## How did you test it? I added both tests and benchmarks to ensure the ackManager worked as before ## Potential risks None. ## Is hotfix candidate? No