fix: replace naive FIFO with LRU cache eviction for WebGL retained geometry (fixes #8597)#8598
Open
MASTERsj01 wants to merge 1 commit intoprocessing:mainfrom
Open
fix: replace naive FIFO with LRU cache eviction for WebGL retained geometry (fixes #8597)#8598MASTERsj01 wants to merge 1 commit intoprocessing:mainfrom
MASTERsj01 wants to merge 1 commit intoprocessing:mainfrom
Conversation
The retained geometry cache in p5.RendererGL.Retained.js had a hard-coded 1000-entry limit with naive FIFO eviction that always deleted the first (oldest created) geometry, regardless of whether it was still being actively drawn. This could cause shapes to silently disappear in complex scenes with many unique geometries. Changes: - Implement LRU (Least Recently Used) cache eviction strategy - Track geometry usage via _lastUsed timestamp in drawBuffers() - Evict least recently drawn geometry instead of oldest created - Replace console.warn with p5._friendlyError in freeGeometry() This addresses a long-standing TODO in the codebase and prevents silent rendering corruption when the geometry cache is full.
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.
Summary
Replaces the naive FIFO geometry cache eviction in p5.RendererGL.Retained.js with a proper LRU (Least Recently Used) strategy that prevents silent rendering corruption.
Resolves #8597
Problem
The retained geometry cache had a hard-coded 1000-entry limit (with a long-standing
@TODOcomment) that always evicted the oldest created geometry viaObject.keys()[0], regardless of whether it was still being actively drawn. This caused shapes to silently disappear in complex scenes.Changes
_lastUsedtimestamp viaperformance.now()in drawBuffers()console.warn→p5._friendlyError()in freeGeometry()Before vs After
Before: Cache full → delete
Object.keys()[0](oldest created, possibly still drawn) → silent rendering failureAfter: Cache full → find entry with smallest
_lastUsed→ delete least recently drawn → active shapes preservedNotes