:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
perf(persons): copy only top-level fields in personhog store snapshots (#116331)
Zach Brown6e08f7e94dc3
diff --git a/nodejs/src/ingestion/common/persons/personhog-persons-store.test.ts b/nodejs/src/ingestion/common/persons/personhog-persons-store.test.tsindex 6c2a83f14051..97c35f066402 100644--- a/nodejs/src/ingestion/common/persons/personhog-persons-store.test.ts+++ b/nodejs/src/ingestion/common/persons/personhog-persons-store.test.ts@@ -281,12 +281,15 @@ describe('PersonhogPersonsStore', () => {expect(sent.setProperties).toEqual({})})- it('memoizes update fetches per batch, resolving once and reading state once', async () => {+ it('memoizes update fetches per batch, resolving once, reading state once, and handing out copies', async () => {repository.resolvePersonsByDistinctIds.mockResolvedValue([{ teamId: 1, distinctId: 'd1', person }])repository.fetchPersonById.mockResolvedValue({ ...person })const bound = store.forBatch(0)- await bound.fetchForUpdate(1, 'd1')- await bound.fetchForUpdate(1, 'd1')+ const first = await bound.fetchForUpdate(1, 'd1')+ // The personless step blanks properties on the person it reads.+ first!.properties = {}+ const second = await bound.fetchForUpdate(1, 'd1')+ expect(second?.properties).toEqual({ plan: 'free' })expect(repository.resolvePersonsByDistinctIds).toHaveBeenCalledTimes(1)expect(repository.fetchPersonById).toHaveBeenCalledTimes(1)})diff --git a/nodejs/src/ingestion/common/persons/personhog-persons-store.ts b/nodejs/src/ingestion/common/persons/personhog-persons-store.tsindex 78b3c2769efa..52ee0e2db599 100644--- a/nodejs/src/ingestion/common/persons/personhog-persons-store.ts+++ b/nodejs/src/ingestion/common/persons/personhog-persons-store.ts@@ -305,11 +305,11 @@ export class PersonhogPersonsStore implements PersonsStore {this.teamGeneration.set(teamId, this.generationOf(teamId) + 1)}- /** Callers get copies, so stamping a result cannot edit the shared cache. */+ /** Shallow: callers may replace fields, but never edit properties in place. */private snapshot(person: InternalPerson): InternalPersonprivate snapshot(person: InternalPerson | null): InternalPerson | nullprivate snapshot(person: InternalPerson | null): InternalPerson | null {- return person === null ? null : { ...person, properties: { ...person.properties } }+ return person === null ? null : { ...person }}/**@@ -724,7 +724,7 @@ export class PersonhogPersonsStore implements PersonsStore {// outdates the view; the install declines and the next touch// re-resolves, while the lane keeps the ops.if (generation === this.generationOf(person.team_id)) {- this.projections.set(personKey, this.snapshot(projected))+ this.projections.set(personKey, projected)this.setDistinctIdToPersonId(`${person.team_id}:${distinctId}`, personKey)this.trackBatchEntry(batchId, `${person.team_id}:${distinctId}`)}