Skip to content

avatar_panel: re-read the avatar catalog only when its revision moves - #968

Merged
transfix merged 1 commit into
masterfrom
perf/avatar-panel-catalog-rev
Nov 2, 2026
Merged

transfix merged 1 commit into
masterfrom
perf/avatar-panel-catalog-rev

Conversation

@transfix

@transfix transfix commented Nov 2, 2026

Copy link
Copy Markdown
Owner

avatar_panel::update runs every frame from arigl's ConferenceSession::step_room. Each call re-read the room's whole avatar catalog with read_avatar_catalog, then resolved our look again. That read walks every option's nodes: 11 colours and 7 accessories with their parts, a few hundred lookups plus a deep children() walk. In the browser build that was most of the ~3.3 ms of the room step spent outside the pump and the view.

Now update reads the catalog only when it can have changed:

  • Catalog: each frame it reads one leaf, conf.rooms.<room>.avatars.rev. It reads the catalog again only when that revision or the room changes. write_avatar_catalog writes the revision last, so a new revision means the options it covers are already there. room_view::sync_looks relies on the same idiom.
  • Choice: it reads our two choice leaves (participants.<pid>.avatar.{color,accessory}) every frame, which costs about the same as a revision check. It resolves the look again only when the catalog, the choice or the pid changed. I left the choice unthrottled: a timer would delay our own pick by up to a second, and a childChanged watch would add lifetime and threading hazards for no gain I could measure.

The published self.avatar.* model is unchanged. The new test checks the labels against a fresh full read after every change.

Measured

This was a native Windows Release build (static, MSVC 14.44) of room_avatar_test. The setup was the default catalog seeded, 8 peers with choices and pose subtrees, and a physics client holon. I timed 2,000 update() calls after a warm-up, using a temporary timing case that is not committed:

per update() call
master (bafcd78b) 1.43 ms (1,424 to 1,444 µs over 3 runs)
this branch 11.3 µs (11.1 to 11.8 µs over 5 runs)

That is about 126× less. In the same binary, the old per-frame sequence on its own (read_avatar_catalog + read_avatar_choice + resolve_avatar_look) still measures ~1.39 ms, so the gain comes from skipping that read.

The remaining ~11 µs is almost all three leaf lookups: the revision plus the two choice leaves, ~3.6 µs each in state::findDescendant. The holon reads take 0.1 µs. The browser build was about 2.3× slower than this native build on the old path (~3.3 ms against 1.43 ms). At that ratio the room step should drop from ~3.8 ms to ~0.5 ms, roughly the cost of the pump plus the view. I have not measured this in the browser.

Two follow-ups, not in this PR:

  • conference_roster.ari's on_tick calls room-avatar-options twice and room-avatar once per tick. Each call does a full read_avatar_catalog, which is the same cost in the document lane.
  • findDescendant is ~3.6 µs for a 7-segment path. It normalizes by split, locale trim and join, then splits and trims again. Every state read pays this.

Test

RoomAvatar.ThePanelRereadsTheCatalogOnlyWhenItChanges (room_avatar_test). It needs no Jolt, so it runs on every builder. It checks that:

  • before the relay's catalog arrives, the panel shows no labels and reads the catalog once over five frames;
  • when the catalog arrives, it shows on the next frame, and a second of unchanged frames reads nothing more;
  • our own pick reaches the panel on the next frame without a catalog read;
  • when the relay rewrites the catalog (a relabelled colour, a withdrawn accessory), the panel reads it once and resolves the fallback;
  • another room means another catalog.

After every change, the published labels equal what a fresh read_avatar_catalog plus resolve_avatar_look gives, which is what update computed every frame before this change.

avatar_panel::update runs every frame from arigl's step_room and re-read
the room's whole avatar catalog each time: every option's nodes, a few
hundred lookups and a deep children() walk. That was most of a browser
client's room step outside the pump and the view.

update() now checks one leaf, the catalog's revision (bumped last by
write_avatar_catalog, the idiom room_view::sync_looks already uses), and
reads the catalog again only when it or the room changes. Our choice is
two leaves, still checked every frame so our own pick shows at once; the
look is re-resolved only when the catalog, the choice or the pid changed.
The published self.avatar.* model is unchanged.

Native Release (static, MSVC), default catalog plus 8 peers:
update() 1.43 ms -> 11.3 us per call. What remains is the three leaf
lookups (~3.6 us each in findDescendant).

Test: RoomAvatar.ThePanelRereadsTheCatalogOnlyWhenItChanges -- the
catalog's arrival, our pick and a rewritten catalog each reach the
published look on the next frame, equal to a fresh read, while unchanged
frames read no catalog.
@transfix
transfix merged commit 4c41a69 into master Nov 2, 2026
27 checks passed
@transfix
transfix deleted the perf/avatar-panel-catalog-rev branch November 2, 2026 07:59
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