Skip to content

Update: Use incremental step building for large event counts#46

Closed
FL4TLiN3 wants to merge 1 commit intomainfrom
perf/optimize-buildsteps
Closed

Update: Use incremental step building for large event counts#46
FL4TLiN3 wants to merge 1 commit intomainfrom
perf/optimize-buildsteps

Conversation

@FL4TLiN3
Copy link
Contributor

@FL4TLiN3 FL4TLiN3 commented Dec 4, 2025

Summary

  • Refactor buildSteps to support incremental updates instead of rebuilding from scratch on every event
  • Use useRef to maintain stepMap across renders for O(1) event processing
  • Process only the new event when adding events, instead of iterating through all events
  • Full rebuild only occurs when MAX_EVENTS is exceeded or when loading historical events

This optimization reduces the time complexity from O(n) to O(1) for each addEvent call, which improves performance for long-running sessions with high event counts.

Closes #42

Test plan

  • Run a session with 100+ events and verify step rendering works correctly
  • Verify historical events load correctly
  • Verify MAX_EVENTS truncation works correctly

Note

Adds packages/tui/apps/start/app.tsx implementing the Start TUI App (steps rendering, browsing router, run settings) and includes a code review report document.

  • TUI App (Start):
    • Add packages/tui/apps/start/app.tsx exporting App that composes useAppState with Step, BrowserRouter, and RunSetting.
    • Renders completed and current steps via Static/Step, shows BrowserRouter while browsing states, and RunSetting during editing/running.
  • Docs:
    • Add CODE_REVIEW_REPORT.md with findings and recommendations for @perstack/tui.

Written by Cursor Bugbot for commit a462d50. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Dec 4, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
perstack Ready Ready Preview Comment Dec 4, 2025 7:05am

@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@FL4TLiN3 FL4TLiN3 force-pushed the perf/optimize-buildsteps branch from 0e53728 to 708b00c Compare December 4, 2025 07:45
@vercel
Copy link

vercel bot commented Dec 4, 2025

Deployment failed with the following error:

Resource is limited - try again in 11 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/fl4tlin3s-projects?upgradeToPro=build-rate-limit

setSteps(buildStepsFromMap(stepMapRef.current))
}
processedCountRef.current = newEvents.length
return newEvents
Copy link

Choose a reason for hiding this comment

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

Bug: Side effects inside setState updater break React patterns

The addEvent function performs side effects (mutating stepMapRef.current via processEvent and calling setSteps) inside the setEvents updater function. React expects state updater functions to be pure. In React's Strict Mode or Concurrent Mode, updaters may be invoked multiple times for verification, causing the ref to be mutated multiple times while only one state update commits. Although the current operations are mostly idempotent, this pattern can cause the ref and state to become desynchronized under certain React scheduling scenarios, potentially leading to stale or inconsistent UI state.

Fix in Cursor Fix in Web

Revert to the original useMemo-based implementation instead of incremental updates.
The optimization caused issues with React patterns (side effects in setState updater)
and historical event handling. The simpler approach is more maintainable and follows
React best practices.
@FL4TLiN3 FL4TLiN3 force-pushed the perf/optimize-buildsteps branch from 708b00c to a462d50 Compare December 4, 2025 08:04
@FL4TLiN3 FL4TLiN3 closed this Dec 4, 2025
@FL4TLiN3 FL4TLiN3 deleted the perf/optimize-buildsteps branch December 4, 2025 08:05
2. **Short-term**: Reduce code duplication in `apps/` directory
3. **Long-term**: Consider performance optimization for high event counts

The codebase follows the project's coding standards (no comments, minimal blank lines, English only) and integrates cleanly with `@perstack/core` types.
Copy link

Choose a reason for hiding this comment

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

Bug: Code review report accidentally committed to repository

The CODE_REVIEW_REPORT.md file appears to be an internal code review document that was accidentally committed to the repository. This file contains review notes, recommendations, and action items that are typically shared separately rather than being part of the codebase. The PR title mentions "incremental step building" but this file is unrelated documentation that exposes internal review findings and should likely be removed before merging.

Fix in Cursor Fix in Web

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.

Performance: Optimize buildSteps for large event counts

1 participant