Skip to content

feat(edit): read only the requests added since an earlier read - #336

Merged
agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:feat/edit-requests-since
Oct 11, 2026
Merged

agviegas merged 1 commit into
ThatOpen:mainfrom
rihokirss:feat/edit-requests-since

Conversation

@rihokirss

Copy link
Copy Markdown
Contributor

Description

Closes #333.

editor.getModelRequests() copies the whole request log out of the worker. Code that follows the log after each edit copies it again every time, which grows with every unsaved edit. This adds editor.getModelRequestsSince(modelId, from = 0, generation = -1), which returns { generation, from, count, requests }: only the requests from from on.

  • VirtualFragmentsModel.getRequestsSince(from, generation) returns the requests after from if the log only grew since generation. If not, it returns all of them from 0, so a caller never misses a change.
  • The generation changes in undo, selectRequest, setRequests and reset. Appends (edit, redo, save) keep it.
  • Main thread: Editor.getModelRequestsSince → EditHelper.getRequestsSince → FragmentsModel._getRequestsSince → _invoke("getRequestsSince").
  • SingleThreadedFragmentsModel.getRequestsSince(from?, generation?).
  • New EditRequestsSince type in Utils/edit/edit-types.ts.
  • virtual-model/requests-since.test.ts covers:
    • appended reads return only the new requests;
    • undo, selectRequest, setRequests and reset return everything;
    • a from the log does not have returns everything.
  • CHANGELOG entry under Unreleased / Features.

getModelRequests is unchanged. History panels that also need undoneRequests keep using it.

Additional context

In an authoring app that reads the log after every edit, this cut an edit at 40 unsaved steps from 339 ms to about 165 ms (see #333). yarn test (all 29 files), tsc -p tsconfig-build.json and yarn build-core pass.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following:

  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Follow the Conventional Commits v1.0.0 standard for PR naming (e.g. feat(examples): add hello-world example).
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

editor.getModelRequests() copies the whole request log out of the worker.
Code that follows the log after each edit (to map the ids of created
items, or to see what changed) copies it again every time, so each read
costs more the longer a session goes without saving, especially when
requests carry large data such as metadata updates.

editor.getModelRequestsSince(modelId, from, generation) returns the
requests from `from` on, the request count and a generation of the log.
The generation changes when the log changes other than by appending
(undo, selectRequest, setRequests, reset); a read with an older
generation, or a `from` the log does not have, returns all requests
from 0. SingleThreadedFragmentsModel gets the same getRequestsSince().
agviegas added a commit that referenced this pull request Oct 11, 2026
A model saved or loaded again under the same id started its request log generation at 0 again, so a reader holding the old generation was handed an empty tail and missed the edits made after the save. Each model instance now starts its generation at a random 32-bit integer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agviegas
agviegas merged commit a117ddd into ThatOpen:main Oct 11, 2026
1 check passed
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.

Read only the edit requests added since an earlier read

2 participants