perf(generation): index assigned images by id in fixElementDefaults#701
Merged
wyuc merged 2 commits intoJun 30, 2026
Merged
Conversation
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
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
fixElementDefaults(lib/generation/scene-generator.ts) corrects image-element aspect ratios by looking up each image’s metadata with.findinside the per-element.map:→ 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 asassignedImages.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/eslintclean (the 2 eslint warnings in the file are pre-existing unused imports, unrelated to this change).No user-facing strings (no i18n impact).