Skip to content

perf(generation): index assigned images by id in fixElementDefaults#701

Merged
wyuc merged 2 commits into
THU-MAIC:mainfrom
ly-wang19:perf/scene-generator-image-lookup-map
Jun 30, 2026
Merged

perf(generation): index assigned images by id in fixElementDefaults#701
wyuc merged 2 commits into
THU-MAIC:mainfrom
ly-wang19:perf/scene-generator-image-lookup-map

Conversation

@ly-wang19

Copy link
Copy Markdown
Contributor

What & why

fixElementDefaults (lib/generation/scene-generator.ts) corrects image-element aspect ratios by looking up each image’s metadata with .find inside the per-element .map:

const imgMeta = assignedImages.find((img) => img.id === imageEl.src); // O(m) per element

→ the pass is O(elements × assignedImages). Most noticeable when a multi-page PDF supplies many assigned images and a slide has several image elements.

Closes #700.

Fix

Index assigned images by id once before the map, then do an O(1) Map.get. Behaviour is identical — Map.get(src) returns the same entry as assignedImages.find(img => img.id === src) — so this is purely the lookup mechanism, no logic change.

Honest scope

Modest in absolute terms (it runs during the seconds-long LLM generation, not a per-frame hot path), but a clean, localized O(n·m) → O(n) with a 6-line diff. No test: it’s a behaviour-preserving lookup-mechanism swap in an internal helper (the surrounding aspect-ratio logic is unchanged). tsc/prettier/eslint clean (the 2 eslint warnings in the file are pre-existing unused imports, unrelated to this change).

No user-facing strings (no i18n impact).

fixElementDefaults looked up each image element's metadata with
assignedImages.find inside the per-element map, making the pass
O(elements × images). Build a Map<id, image> once and use an O(1)
Map.get lookup instead. Behavior is identical (Map.get returns the same
entry as the find), so it's purely a lookup-mechanism swap.

Closes THU-MAIC#700
@wyuc wyuc merged commit b516427 into THU-MAIC:main Jun 30, 2026
2 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.

fixElementDefaults does a per-element image lookup — O(elements × images)

2 participants