Skip to content

Reduce logs memory and CPU consumption#662

Merged
micheal-parks merged 4 commits intomainfrom
logs-perf-improvements
May 8, 2026
Merged

Reduce logs memory and CPU consumption#662
micheal-parks merged 4 commits intomainfrom
logs-perf-improvements

Conversation

@micheal-parks
Copy link
Copy Markdown
Member

@micheal-parks micheal-parks commented May 8, 2026

After profiling with claude I discovered that the current logs setup is eating a shocking amount of CPU and memory. It's likely causing a lot of performance issues I'm witnessing on the Quest headset. This PR substantially reduces the problem, with the following graph representing profiles before / after:

Screenshot 2026-05-08 at 11 17 39

Details of the changes are in comments.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 8, 2026

🦋 Changeset detected

Latest commit: 2f40292

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@viamrobotics/motion-tools Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

class="relative h-[calc(100%-33px)]"
>
{@render children()}
{#if isOpen}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Main optimization. The logs panel can churn the dom pretty hard when errors are flooding in at 30-60fps.

Comment thread src/lib/ecs/hierarchy.ts
* dance otherwise flips `useParentName` to `undefined` and back, remounting
* every `<Portal id={parent.current}>` subtree per tick.
*/
export const setParent = (entity: Entity, name: string | undefined): void => {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Smaller but important optimization, prevents entire tree remounts under certain situations

// Hot path is `Map.set` (or in-place `count++`) plus `version++` — no
// array allocation per add. The display arrays are materialized lazily
// in `$derived.by`, so a closed logs panel costs nothing.
const entries = new Map<string, Log>()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Second major optimization. Since deriveds are read lazily, there should be barely any CPU activity for logs unless a user has opened the logs tab.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-05-08 15:31 UTC

@micheal-parks micheal-parks merged commit 142223f into main May 8, 2026
14 checks passed
@micheal-parks micheal-parks deleted the logs-perf-improvements branch May 8, 2026 15:30
This was referenced May 8, 2026
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.

2 participants