Repository navigation
perf(backend): clean up hot-path allocations and bound the count cache (WI-1917) - #437
Merged
Merged
Conversation
…e (WI-1917) - Remove the redundant second arg-building loop in GetTimeRollup. - Hoist the ItemRepository onto HierarchyService and PermissionService instead of allocating one per call in hot helpers. - Fold the item-list count cache generation into its entry and add an opportunistic sweep, so the per-workspace map is count-bounded and cannot grow under workspace churn. A generation tombstone is only dropped once it has been expired longer than a load can be in flight. - Give the SQLite read and write pools the same connection lifetimes as Postgres (30m lifetime / 5m idle). Recorded findings: the rate-limiter buckets are already bounded (sharded, per-shard cap, idle sweep, LRU eviction), and the migration runner loads applied versions in one query — per-migration idempotency checks only run for unapplied migrations. A test now pins that.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
P2 cleanup from
docs/backend-performance-scaling-review.md. The effective-project cache was split into WI-1964, so this is the mechanical remainder.What
GetTimeRollup(item_hierarchy.go): drop the redundant second loop that re-assigned the args slice it had just built.NewItemRepository(db)per call:HierarchyServiceallocated one in 12 methods andPermissionService.GetItemWorkspaceIDin one. Both now hold a single*repository.ItemRepository.itemListCountCachebound (item_count_cache.go): the generation now lives in the entry (as a tombstone after invalidation) instead of a second unbounded map, and an opportunistic sweep keeps the map count-bounded. A tombstone is only dropped once it has been expired longer than a load can still be in flight, so an invalidated in-flight load can never store its stale count.database.go): the read and write pools now setSetConnMaxLifetime(30m)/SetConnMaxIdleTime(5m), matching Postgres.Findings recorded (no code change)
internal/ratelimit/limiter.go): 64 shards, per-shard cap, 10 min idle sweep, andmakeRoomLRU eviction.runPendingMigrationsloads applied versions in one query and skips them in memory; the per-migration idempotency predicates only run for migrations that are not stamped. A test now pins that.Verification
go build ./internal/...,go vet— passgolangci-linton the changed packages — 0 issuesinternal/repository/...— pass (31.5s)internal/database/...— pass, except the pre-existingTestCompactCatalogContainsExactlyRetainedMigrations(fails onmaintoo: catalog length 120 vs want 115)internal/services/...— pass, except the pre-existingTestItemWorkspaceMovePreviewsAndCommitsExactPolicy(fails onmaintoo)Pairs with Windshiftapp/core-tests-internal#35.