Skip to content

Plugin clients: patch the cached snapshot after the plugin's own edits - #3478

Merged
HakanSeven12 merged 1 commit into
HakanSeven12:mainfrom
D-Fed11:pr/plugin-client-snapshot-cache
Nov 23, 2026
Merged

HakanSeven12 merged 1 commit into
HakanSeven12:mainfrom
D-Fed11:pr/plugin-client-snapshot-cache

Conversation

@D-Fed11

@D-Fed11 D-Fed11 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

The out-of-process plugin clients (V2/V3 PluginHostApi and V4 V4PluginHostApi) cache one document snapshot, but dropped it after every entity add/update/remove, so the next document() re-transferred the whole drawing. They also answered every read_record with a host round trip, even for entities that have no record. On a drawing of tens of megabytes, a plugin command that edits or scans entity by entity took minutes (one measured case: 5.5 min → about 20 s).

GetEntitiesBatch already exists for exactly this ("a plugin that writes and re-reads never re-clones the full document snapshot"); the clients now use it.

Changes

  • New ipc/snapshot_patch.rs (shared by both clients):
    • apply_refreshed: replace/insert the host's post-edit copies of the touched entities and drop removed ones;
    • mirror_record: apply a successful WriteRecord/RemoveRecord to the cached entity exactly as the host does (replace or drop the app's record and its verbatim DWG EED);
    • edit_needs_full_refresh: attribute edits (stored inside their block reference).
  • Both clients: after add_entity/add_entities/update_entity/remove_entity/update_entities_transaction, re-read only the touched handles with GetEntitiesBatch and patch the cache; read_record is answered from the snapshot when the entity is in it; record writes/removals are mirrored.
  • The cache is still dropped (the next read fetches a fresh snapshot) whenever a patch cannot be exact: a failed or short batch answer, an edited attribute, an entity on a layer the cached layer table does not know (the host created it), a record of an application the cached APPID table does not know, or a degraded snapshot (V2/V3).
  • XRecord, reference-only and other operations keep dropping the cache as before.

Testing

  • 8 new tests: 4 client tests with a scripted host checking the exact request sequence (update → GetEntitiesBatch, no second DocumentSnapshot; records served from and mirrored into the snapshot; a new APPID and a failed batch both refetch), 4 unit tests for snapshot_patch.
  • cargo test -p ocs_plugin_api --features host --lib (204 passed), cargo test -p ocs_plugin_api.
  • Used with a plugin that converts ~900 blocks on a 50k-entity drawing.

🤖 Generated with Claude Code

An out-of-process plugin's client dropped its whole document snapshot after
every entity add/update/remove, so the next read re-transferred the entire
drawing; it also answered every read_record with a round trip, even for
entities without a record. On a drawing of tens of megabytes a command that
edits or scans entity by entity took minutes.

Both clients (V2/V3 and V4) now re-read only the entities they changed with
GetEntitiesBatch and patch the cached snapshot with the host's post-edit
copies, mirror their own record writes and removals the way the host applies
them, and answer read_record from the snapshot when the entity is in it. The
cache is still dropped, and the next read fetches a fresh snapshot, whenever
a patch cannot be exact: a failed or short batch read, an edited attribute
(stored inside its block reference), an entity on a layer the cached table
does not know, or a record of an application the cached APPID table does not
know.
@HakanSeven12
HakanSeven12 merged commit 9df4c31 into HakanSeven12:main Nov 23, 2026
8 checks 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.

2 participants