Skip to content

Commit

Permalink
Add detail to Java Units documentation (wpilibsuite#2397)
Browse files Browse the repository at this point in the history
* Add detail to Java Units documentation

* Add Java GC

* PR comments

* Add section about Generics and the verbose syntax

* Correct typo (still exists in Javadoc)

* Remove object pooling

* Fix heading structure

* Consistent defined termininology for dimension, unit, and measure

* More review comments

* Last of the review comments

* Add use of volts per meter per second
  • Loading branch information
agasser authored Nov 30, 2023
1 parent 8d41557 commit c0859a4
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 43 deletions.
1 change: 1 addition & 0 deletions source/docs/software/basic-programming/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Basic Programming
using-test-mode
reading-stacktraces
functions-as-data
java-gc
31 changes: 31 additions & 0 deletions source/docs/software/basic-programming/java-gc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Java Garbage Collection
=======================
Java garbage collection is the process of automatically managing memory for Java objects. The Java Virtual Machine (JVM) is responsible for creating and destroying objects, and the garbage collector is responsible for identifying and reclaiming unused objects.

Java garbage collection is an automatic process, which means that the programmer does not need to explicitly deallocate memory. The garbage collector keeps track of which objects are in use and which are not, and it periodically reclaims unused objects.

Object Creation
---------------

Creating a large number of objects in Java can lead to memory and performance issues. While the Java Garbage Collector (GC) is designed to handle memory management efficiently, creating too many objects can overwhelm the GC and cause performance degradation.

Memory Concerns
^^^^^^^^^^^^^^^

When a large number of objects are created, it increases the overall memory footprint of the application. While the overhead for a single object may be insignificant, it can become substantial when multiplied by a large number of objects.

Performance Concerns
^^^^^^^^^^^^^^^^^^^^

The GC's job is to periodically identify and reclaim unused objects in memory. While garbage collection is running on an FRC robot coded in Java, execution of the robot program is paused. When the GC has to collect a large number of objects, it has to pause the application to run more frequently or for longer periods of time. This is because the GC has to perform more work to collect and process each object.

GC-related performance degradation in robot programs can manifest as occasional pauses, freezes, or loop overruns as the GC works to reclaim memory.

Design Considerations
^^^^^^^^^^^^^^^^^^^^^

If you anticipate your application creating a large number of short-lived objects, it is important to consider design strategies to mitigate the potential memory and performance issues. Here are some strategies to consider:

- Minimize object creation: Carefully evaluate the need for each object creation. If possible, reuse existing objects or use alternative data structures, such as arrays or primitives, to avoid creating new objects.

- Efficient data structures: Use data structures that are well-suited for the type of data you are working with. For example, if you are dealing with a large number of primitive values, consider using arrays or collections specifically designed for primitives.
Loading

0 comments on commit c0859a4

Please sign in to comment.