Skip to content

no need to clone before setting items in cache. - #3403

Merged
danoswaltCL merged 2 commits into
devfrom
wip/no-cache-copy-on-refresh
Nov 5, 2026
Merged

danoswaltCL merged 2 commits into
devfrom
wip/no-cache-copy-on-refresh

Conversation

@danoswaltCL

@danoswaltCL danoswaltCL commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

See the comments in the code, they explain it well. This only comes up during background cache refresh, but it simply doesn't need to happen, so every bit helps flatten the long tail of latency when other requests are queuing behind during bursty periods.

@danoswaltCL
danoswaltCL requested review from zackcl and a balanced review from Copilot October 27, 2026 15:56
@danoswaltCL
danoswaltCL requested a review from bcb37 October 27, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused configuration change is consistent with shared cache reads, and the added regression tests cover object identity and mutation risks.

No open issues 🎉

What changed in this PR

This PR removes deep cloning when storing values in the backend’s in-memory cache, reducing blocking work during cache loads and background refreshes.

Changes:

  • Disables shouldCloneBeforeSet and documents the shared-object mutation risk.
  • Adds tests for object identity on cache misses, hits, refreshes, and bulk loads.
  • Adds regression tests checking that assignment and feature-flag requests leave cached data unchanged.
File Description
packages/​backend/​test/​unit/​services/​FeatureFlagService.test.ts Checks cached flags and precomputed rows remain unchanged across requests.
packages/​backend/​test/​unit/​services/​ExperimentAssignmentService.test.ts Checks cached segments and precomputed rows remain unchanged during assignment.
packages/​backend/​test/​unit/​services/​CacheService.test.ts Verifies the real memory store retains loaded objects without copying.
packages/​backend/​src/​api/​services/​CacheService.ts Disables cloning before cache writes and documents the rationale.

Review effort: Balanced

const before = snapshot();

await testedModule.getAllExperimentConditions(userDoc, context, loggerMock);
await testedModule.getAllExperimentConditions(userDoc, context, loggerMock);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're making sure to have regression coverage for places where cache mutations could be added, shouldn't we also include tests for the /mark path. I only see tests for the /assign path here.

@bcb37 bcb37 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. Just one question.

@danoswaltCL

Copy link
Copy Markdown
Collaborator Author

yes that's true i can add that

@danoswaltCL
danoswaltCL force-pushed the wip/no-cache-copy-on-refresh branch from f9fc557 to 8a4540d Compare November 5, 2026 01:07
@danoswaltCL
danoswaltCL requested a review from bcb37 November 5, 2026 01:08
@danoswaltCL

Copy link
Copy Markdown
Collaborator Author

@bcb37 i added tests for mark and reward paths, which would both be implicated.

@danoswaltCL
danoswaltCL merged commit 303ab31 into dev Nov 5, 2026
6 checks passed
@danoswaltCL
danoswaltCL deleted the wip/no-cache-copy-on-refresh branch November 5, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants