Skip to content

perf: reduce inline object memory churn in 3D warp mode#121

Merged
orhun merged 2 commits into
orhun:mainfrom
jackthepunished:perf/inline-object-memory
Jul 5, 2026
Merged

perf: reduce inline object memory churn in 3D warp mode#121
orhun merged 2 commits into
orhun:mainfrom
jackthepunished:perf/inline-object-memory

Conversation

@jackthepunished

@jackthepunished jackthepunished commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #120

Summary

  • Stop rebuilding all inline scene entities every frame in 3D warp mode; animate Kitty image planes in place instead (same approach as animate_terminal_plane_warp for the terminal surface)
  • Reuse cached Kitty plane mesh/material handles across syncs and remove stale assets when layout subdivisions change
  • Move Kitty RGBA bytes into the Bevy Image on upload instead of keeping a duplicate copy in the inline registry
  • Reuse STL extruded mesh handles keyed by depth and remove superseded OBJ/STL mesh assets when extrusion depth changes

Problem

In 3D presentation with warp active, sync_inline_objects ran every frame via force_warp_sync, despawned all inline entities, and respawned meshes/materials without cleaning up Bevy asset stores. Kitty images also kept a full RGBA copy after GPU upload.

Approach

  • Remove force_warp_sync; inline sync now runs only when TerminalInlineObjects::needs_sync() is true
  • Add animate_inline_kitty_planes to update Kitty plane vertex positions in place during warp animation
  • Cache plane assets on KittyInlineObject and drop registry-side RGBA after first upload
  • Align STL mesh caching with the existing OBJ depth-key pattern

Benchmarks

Measured locally on Windows, release build.

Idle 2D (~30s): no meaningful change (~833 MB working set before and after)

3D + warp + inline RGP object (~3 min, sampled every 15s):

Before After
Steady-state working set ~962 MB ~863 MB
Growth over 3 min +7.6 MB, then flat +2.1 MB, flat

Test plan

  • cargo check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • Manual smoke test: 2D terminal, 3D toggle, warp, inline RGP object
  • Kitty inline images in 3D warp mode
  • macOS / Linux sanity check

Stop per-frame inline entity rebuilds during warp animation, reuse cached
Kitty plane assets, drop duplicate RGBA after upload, and clean up
superseded RGP mesh handles when extrusion depth changes.

Fixes orhun#120
Copilot AI review requested due to automatic review settings July 2, 2026 13:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces memory churn and asset growth in 3D presentation when warp is active by avoiding per-frame inline entity rebuilds and by reusing cached GPU assets for inline Kitty and RGP objects.

Changes:

  • Stop forcing sync_inline_objects every frame during warp; instead animate Kitty plane vertices in place via a new animate_inline_kitty_planes system.
  • Cache Kitty plane mesh/material handles (and move Kitty RGBA bytes into the Bevy Image on first upload).
  • Reuse depth-keyed STL extruded mesh handles and remove superseded OBJ/STL mesh assets when extrusion depth changes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/systems.rs Removes per-frame warp sync for inline objects, adds Kitty plane asset caching + in-place vertex animation, and cleans up superseded OBJ/STL mesh assets on depth changes.
src/plugin.rs Wires the new animate_inline_kitty_planes system into the update schedule after sync_inline_objects.
src/kitty.rs Initializes the new Kitty plane cache field when rasterizing decoded Kitty images.
src/inline.rs Introduces InlineKittyPlaneLayout + KittyPlaneCache and extends inline object structs to store cached Kitty plane and STL extruded mesh handles.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/systems.rs
Comment on lines +809 to +815
if !matches!(
presentation.mode,
TerminalPresentationMode::Plane3d | TerminalPresentationMode::Mobius3d
) || warp.amount <= 0.0
{
return;
}
Comment thread src/inline.rs
Comment on lines 558 to 565
pub struct KittyInlineObject {
/// Raster image payload.
pub raster: RasterObject,
/// Indicates placeholder-driven placement.
pub uses_placeholders: bool,
/// Cached plane mesh and material for 3D presentation.
pub(crate) plane: Option<KittyPlaneCache>,
}

@orhun orhun left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@orhun orhun merged commit 1e0aa3b into orhun:main Jul 5, 2026
11 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.

perf: inline object memory churn in 3D warp mode

3 participants