Skip to content

perf!: Save state only when it has changed - #2491

Open
Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:recoverable-state-skip-unchanged
Open

Mantisus wants to merge 2 commits into
apify:v2from
Mantisus:recoverable-state-skip-unchanged

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

On a PERSIST_STATE event and on exit, components that keep a persisted state, such as the session pool, request loaders and the use_state dictionary, now write it only when it has changed since it was last saved or loaded. An unchanged state no longer rewrites its record at each persist interval. A direct persist_state() call and KeyValueStore.persist_autosaved_values() still write every time, so the end of a run still saves the use_state dictionary. After a failed write, the next event writes the state again.

Depends on #2490.

Testing

  • Unit tests for skipping an unchanged state on events and on exit, direct writes, failed writes (including one that still lands) and a change made during a write.
  • Unit tests for loading a record, a cancelled load, clearing the record with reset_store() and the record format.

✍️ Drafted by Claude Code

@Mantisus Mantisus self-assigned this Nov 22, 2026
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 22, 2026
@Mantisus
Mantisus requested a review from vdusek November 22, 2026 15:11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant