-
Notifications
You must be signed in to change notification settings - Fork 59
Description
In convertUpdateResultsAPIObjToExperimentResultData()
, a new IntervalResults
object is being created inside the loop for each metric. However, only the last created object is retained in the resultsMap
, making all previously created IntervalResults objects redundant and subject to garbage collection.
This leads to unnecessary object creation and temporary memory pressure.
Proposed Fix:
Refactor the logic to:
- Create the IntervalResults
object once per container (per interval).
- Populate it with the metricResultsMap
after collecting all metrics.
- Then store it in the resultsMap
.
This reduces GC overhead and improves performance.
Memory breakdown of IntervalResults
object:
Field | Type | Size (Compressed) | Size (Uncompressed) | Notes |
---|---|---|---|---|
Object Header | JVM internal | 12 bytes | 16 bytes | Includes mark word and class pointer |
metricResultsMap | HashMap<MetricName, MetricResults> | 4 bytes | 8 bytes | Reference only |
acceleratorMetricResultHashMap | HashMap<MetricName, AcceleratorResult> | 4 bytes | 8 bytes | Reference only |
intervalStartTime | Timestamp | 4 bytes | 8 bytes | Reference only |
intervalEndTime | Timestamp | 4 bytes | 8 bytes | Reference only |
durationInMinutes | Double | 8 bytes | 8 bytes | Primitive (boxed if used externally) |
duration_in_seconds | Double | 8 bytes | 8 bytes | Primitive |
Total (without padding/alignment) | — | 44 bytes | 64 bytes | Minimum memory before alignment/padding |
Actual heap allocation will be rounded up to 8 or 16 byte alignment, so practical sizes may be 48 bytes (compressed) and 64 or 72 bytes (uncompressed).
So the total temporary memory saving would be 48 bytes (As compressed refs are turned on by default in JVM) per request / per timestamp / per kubernetes object / per container / per metric