Skip to content

Comments

Reduce Memory Usage#54

Draft
wilsonwatson wants to merge 4 commits intomainfrom
memoryReduce
Draft

Reduce Memory Usage#54
wilsonwatson wants to merge 4 commits intomainfrom
memoryReduce

Conversation

@wilsonwatson
Copy link
Member

Profiling

Reduces GC pressure by reusing objects that have a lifetime smaller-than-or-equal-to the loop lifetime. This is done by using mutable versions of Translation2d, Rotation2d and Pose2d, which collision response made heavy use of. Over a minute test, these changes reduced the number of allocated bytes by ~78%.

@wilsonwatson wilsonwatson marked this pull request as draft February 2, 2025 20:28
@legoguy1000
Copy link
Member

Should we change all the Units to mutable units as well??

@wilsonwatson
Copy link
Member Author

If it turns out to be an issue we should. Because I was using the default IO implementations here, there weren't any Unit allocs recorded, but we could duplicate this test on the actual robot to check the real IO impls.

@wilsonwatson wilsonwatson marked this pull request as ready for review February 3, 2025 03:24
@legoguy1000
Copy link
Member

Ok, sounds good, lets test today and merge. Any reason this isn't the default for WPILIB?

@legoguy1000
Copy link
Member

can u delete the limelight pipelines folder as well, we've been holding onto this for years

@wilsonwatson
Copy link
Member Author

The reason its not the default is more a Java issue than WPILib. There's some gotchas in how I implemented the mutable versions of the WPILib classes, especially when it comes to aliasing. Those are all nicely avoided in immutable versions, but in Java, those aren't cleaned up when they leave scope. Instead they're cleaned up whenever the JVM thinks is appropriate, but as we've seen in the shop, the JVM on the Rio isn't that smart. For what it's worth, the JVM on my desktop is able to keep memory manageable just fine, but I think the combination of the Rio's poor CPU and small amount of RAM makes Java ill-suited for the idiomatic "everything is immutable" style of programming that Java (and by extension, WPILib) encourages.

@legoguy1000 legoguy1000 marked this pull request as draft March 18, 2025 22:05
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