Performance refactor#362
Open
edwardhorsford wants to merge 5 commits into
Open
Conversation
Clinics now live in a boot-time shared store (deep-frozen in dev) and are attached to each request by middleware; a toJSON override keeps them out of the serialised session. First collection of three - participants and events follow once the write path is funnelled through helpers.
Prepares for serving events and participants from the shared store: - Temp working copies (data.event, data.participant) are now deep clones, so form merges can never write into the source records - Priors, deferral and reading writes build replacement records and save via updateEventData instead of mutating found records in place - Session-copied seed arrays are deep-frozen in development (config escape hatch: freezeSharedData) so leftover in-place writers throw
…s only Sessions now persist only changed records (data._changes, whole records keyed by id, stamped with the data generation they were made against). Middleware overlays them onto the shared store's arrays each request, so routes and views read data.events etc unchanged. - Update helpers write changes to _changes as well as the attached array - generationInfo comes from the store, so a regenerate or profile swap by one session resets data for every session (stale stamps discarded) - Daily regeneration check now reads the store, not the session - Serialised session size drops from ~4.5MB to ~40KB; RSS under a 200-request two-session load roughly halves - New docs/data-conventions.md explains reading vs updating data
npm run generate writes the seed files ahead of boot; heroku-postbuild calls it so dynos start with data on disk. Daily staleness check at runtime is unchanged (dyno cycling keeps dates fresh).
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.
What
Stops copying the whole generated dataset (~4.5MB) into every session, which
was pushing Heroku past its 512MB memory quota.
Seed data (participants, clinics, events) now lives in a shared read-only
store (
app/lib/data-store.js), loaded once at boot and attached to eachrequest by middleware. Sessions only store changed records (
data._changes,whole records keyed by id), overlaid onto the shared arrays per request —
so routes and views read
data.eventsetc exactly as before.Details
data.event,data.participant) are deep clones;all writes funnel through the update helpers
(escape hatch:
freezeSharedData: falsein config)resets data for every session — swap-and-demo keeps working as expected
heroku-postbuild)docs/data-conventions.mdcovers reading vs updating dataNotes for reviewers
participant edit, regenerate, two concurrent sessions