@@ -1155,24 +1155,25 @@ impl Heap {
1155
1155
/// Get a snapshot of current GC performance metrics (calculates derived metrics on-demand)
1156
1156
pub fn gc_metrics ( & self ) -> GCMetrics {
1157
1157
let mut metrics = unsafe { ( * self . gc_metrics . get ( ) ) . clone ( ) } ;
1158
-
1158
+
1159
1159
// Calculate derived metrics on-demand to avoid hot path overhead
1160
1160
let now = Instant :: now ( ) ;
1161
- metrics. performance_counters . heap_lifetime = now. duration_since ( metrics. performance_counters . heap_created_at ) ;
1162
-
1161
+ metrics. performance_counters . heap_lifetime =
1162
+ now. duration_since ( metrics. performance_counters . heap_created_at ) ;
1163
+
1163
1164
// Calculate allocation rates
1164
1165
let heap_lifetime_seconds = metrics. performance_counters . heap_lifetime . as_secs_f64 ( ) ;
1165
1166
if heap_lifetime_seconds > 0.0 {
1166
- metrics. allocation_stats . allocation_rate_bps =
1167
+ metrics. allocation_stats . allocation_rate_bps =
1167
1168
metrics. allocation_stats . total_bytes_allocated as f64 / heap_lifetime_seconds;
1168
- metrics. allocation_stats . allocation_rate_ops =
1169
+ metrics. allocation_stats . allocation_rate_ops =
1169
1170
metrics. allocation_stats . total_objects_allocated as f64 / heap_lifetime_seconds;
1170
1171
}
1171
-
1172
+
1172
1173
// Update utilisation and performance metrics
1173
1174
self . calculate_utilisation_metrics ( & mut metrics) ;
1174
1175
self . calculate_performance_health ( & mut metrics) ;
1175
-
1176
+
1176
1177
metrics
1177
1178
}
1178
1179
@@ -1203,7 +1204,7 @@ impl Heap {
1203
1204
}
1204
1205
}
1205
1206
}
1206
-
1207
+
1207
1208
// In release builds, do nothing to maximize performance
1208
1209
#[ cfg( not( debug_assertions) ) ]
1209
1210
{
@@ -1249,14 +1250,15 @@ impl Heap {
1249
1250
let total_time = now. duration_since ( metrics. performance_counters . heap_created_at ) ;
1250
1251
if total_time. as_secs_f64 ( ) > 0.0 {
1251
1252
metrics. performance_counters . gc_overhead_percent =
1252
- ( metrics. collection_stats . total_gc_time . as_secs_f64 ( ) / total_time. as_secs_f64 ( ) )
1253
+ ( metrics. collection_stats . total_gc_time . as_secs_f64 ( )
1254
+ / total_time. as_secs_f64 ( ) )
1253
1255
* 100.0 ;
1254
1256
}
1255
1257
1256
1258
// Reset allocation burst after collection
1257
1259
metrics. allocation_stats . current_burst_bytes = 0 ;
1258
1260
}
1259
-
1261
+
1260
1262
// In release builds, do nothing
1261
1263
#[ cfg( not( debug_assertions) ) ]
1262
1264
{
@@ -1306,7 +1308,7 @@ impl Heap {
1306
1308
total_bytes_freed / metrics. emergency_stats . successful_collections ;
1307
1309
}
1308
1310
}
1309
-
1311
+
1310
1312
// In release builds, do nothing
1311
1313
#[ cfg( not( debug_assertions) ) ]
1312
1314
{
@@ -1368,7 +1370,6 @@ impl Heap {
1368
1370
1369
1371
/// Calculate performance health indicators on-demand
1370
1372
fn calculate_performance_health ( & self , metrics : & mut GCMetrics ) {
1371
-
1372
1373
// Calculate memory pressure based on allocation rate and collection frequency
1373
1374
let allocation_pressure = if metrics. allocation_stats . peak_allocation_rate_bps > 0.0 {
1374
1375
( metrics. allocation_stats . allocation_rate_bps
0 commit comments