Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 17, 2025

The demo loop visualization polling EphysLink every 10ms dispatched Redux state updates at the same rate, overwhelming the GC.

Changes

ProbeController.cs

  • Added local fields for visualization position updates bypassing Redux:
    • VisualizationLocalAPMLDV, VisualizationLocalDepth, VisualizationLocalAngles, VisualizationLocalForwardT
    • HasVisualizationUpdate flag
  • Added UpdateVisualizationProbePosition() to apply buffered updates

CartesianProbeController.cs, SagittalCoronalProbeController.cs

  • Call UpdateVisualizationProbePosition() in Update() to render buffered positions at frame rate

EphysLinkService.cs

  • UpdateVisualizationProbePosition() writes directly to ProbeController local fields instead of dispatching to Redux
  • Removed bulk dispatch that was triggering state updates every 10ms

Result

EphysLink polls at 10ms for responsive hardware tracking, ProbeController applies updates at Unity frame rate (~60Hz), Redux only updates on user actions. Position threshold (0.0001f) prevents redundant updates.

// Before: 100 Redux dispatches/sec per probe
_storeService.Store.Dispatch(SceneActions.BULK_SET_PROBE_POSITION_AND_ANGLES_BY, requests);

// After: Direct field write, Unity renders at frame rate
probeController.VisualizationLocalAPMLDV = transformedAPMLDV;
probeController.HasVisualizationUpdate = true;
Original prompt

This section details on the original issue you should resolve

<issue_title>Memory leak in automation demo (take 2)</issue_title>
<issue_description>I think there's a memory leak during the demo loop (in ephyslinkservice) visualizing the probe's position creates too many state updates than the GC can clean up. First, identify if this true, then solve this by creating a local field in probecontroller that ephys link service will write APMLDV to and then in probe controller if the probe is a visualization probe have it update its position based on the local position field instead of the state one. Consider doing this with the update() function in probe controller so it will update every frame (if it's a visualization probe). Ephyslinkservice should poll ephys link with a 10 ms delay to give fast updates.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits November 17, 2025 06:39
…oid Redux updates

Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Co-authored-by: kjy5 <82800265+kjy5@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix memory leak in automation demo loop Fix memory leak in demo loop by eliminating Redux state thrashing Nov 17, 2025
Copilot AI requested a review from kjy5 November 17, 2025 06:45
@kjy5 kjy5 marked this pull request as ready for review November 17, 2025 07:16
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.

Memory leak in automation demo (take 2)

2 participants