Skip to content

room intrinsics: re-read the avatar catalog only when its revision moves - #969

Merged
transfix merged 2 commits into
masterfrom
perf/room-avatar-verbs-catalog-rev
Nov 2, 2026
Merged

transfix merged 2 commits into
masterfrom
perf/room-avatar-verbs-catalog-rev

Conversation

@transfix

@transfix transfix commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Once joined, conference_roster.ari's on_tick calls three avatar verbs on every tick:

  • (room-avatar-options ROOM "color")
  • (room-avatar-options ROOM "accessory")
  • (room-avatar HANDLE)

Each verb called read_avatar_catalog, which walks every option's nodes: a few hundred lookups plus a deep children() walk.

Now the document's room_table, which already owns its room handles, keeps each room's catalog together with the revision it was read at. room-avatar-options, room-avatar and room-set-avatar's option check go through room_table::catalog():

  • It reads one leaf, conf.rooms.<room>.avatars.rev. It reads the catalog again only when that revision has moved. write_avatar_catalog writes the revision last, and room_view::sync_looks relies on it the same way. Only the relay writes the catalog (seed_avatar_catalog), and the room write gate keeps clients out of that subtree.
  • The catalog is held by shared_ptr and read outside the table's lock.
  • The revision is read before the catalog. If a write lands mid-read, the cache stores the older revision, so the next call reads again.

The verbs' results are unchanged. This is independent of #968, which applies the same idea to avatar_panel::update, and the two touch different code.

Measured

This was a native Windows Release build (static, MSVC 14.44) of room_avatar_test. A temporary timing case, not committed, ran the roster tick's three verbs in a 200-iteration action program through a Runtime. I subtracted an identical loop with the verbs replaced by trivial calls (11 to 24 µs).

the roster's avatar verbs, per tick
master (a8f2b7c5) 5.0 to 7.1 ms (6 runs, median ≈ 5.2 ms)
this branch 38 to 45 µs (5 runs)

That is about 130× less. What's left is the leaf reads that remain: three revisions, our choice, and room-avatar's policy and reserve. Each costs a few µs in findDescendant. I haven't measured it in the browser build. The wasm client was about 2.3× slower than native on the catalog read.

Test

RoomAvatar.TheAvatarVerbsRereadTheCatalogOnlyWhenItsRevisionMoves (room_avatar_test) runs the verbs through a Runtime, as the roster does:

  • the option lists and our look match a fresh read of the tree;
  • a new pick (room-set-avatar) reaches room-avatar on the next call;
  • a label written behind the revision's back stays unseen. On master this check fails. That is how the test shows an unchanged catalog isn't read again;
  • when the relay rewrites the catalog (a relabelled colour, a withdrawn accessory), the lists match a fresh read, the look falls back to the first accessory, and room-set-avatar refuses the withdrawn accessory;
  • another room means another catalog.

The test clears the global action-intrinsics registry when it ends, as the net-intrinsics tests do.

conference_roster.ari's on_tick calls (room-avatar-options ROOM "color"),
(room-avatar-options ROOM "accessory") and (room-avatar HANDLE) on every
tick once joined, and each did a full read_avatar_catalog: every option's
nodes, a few hundred lookups and a deep children() walk.

The document's room_table now keeps each room's catalog with the
revision it was read at. The three avatar verbs (and room-set-avatar's
check) read one leaf, the catalog's revision, and the catalog again only
when that moved -- write_avatar_catalog bumps it last, the idiom
room_view::sync_looks uses. The catalog is held by shared_ptr and read
outside the table's lock; the revision is read first, so a write landing
mid-read leaves a newer revision for the next call. The verbs' results
are unchanged.

Native Release (static, MSVC), the roster tick's three verbs in an action
program: 5.0-7.1 ms -> 38-45 us per tick.

Test: RoomAvatar.TheAvatarVerbsRereadTheCatalogOnlyWhenItsRevisionMoves
drives the verbs through a Runtime: a new choice and a rewritten catalog
reach them on the next call, equal to a fresh read, while a label changed
behind the revision's back stays unseen (on master that check fails).
…rbs-catalog-rev

# Conflicts:
#	src/cvc/tests/room_avatar_test.cpp
@transfix
transfix merged commit b1c2c6a into master Nov 2, 2026
27 checks passed
@transfix
transfix deleted the perf/room-avatar-verbs-catalog-rev branch November 2, 2026 08:14
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.

1 participant