Skip to content

mem-track: Peak memory tracking options with per-id sampling - #1429

Open
TristonianJones wants to merge 2 commits into
cel-expr:masterfrom
TristonianJones:peak-memory-limits
Open

mem-track: Peak memory tracking options with per-id sampling#1429
TristonianJones wants to merge 2 commits into
cel-expr:masterfrom
TristonianJones:peak-memory-limits

Conversation

@TristonianJones

@TristonianJones TristonianJones commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Using the observer pattern, introduce peak memory tracking using the AggregateSize functions.

The cost of tracking scales with the size of the objects being tracked and the size of the expression.
If inputs in list are expected to be roughly the same size, or there's a high volume of entries, using
sampling to lower the overall cost of tracking while still roughly preserving the intent

Workload Evaluation Configuration Time (ns/op) Cost vs Baseline Memory (B/op) Allocs (allocs/op)
List Concatenation a + a Baseline (None) 205.7 1.00x 288 5
  Cost Tracking 259.4 1.26x 320 6
  Memory Tracking (Sample = 1) 325.7 1.58x 288 5
  Memory Tracking (Sample = 5) 324.7 1.58x 288 5
  State Tracing 284.6 1.38x 288 5
  Cost + Memory Tracking 356.8 1.73x 320 6
  Cost Tracking + State Tracing 316.5 1.54x 320 6
  Memory Tracking + State Tracing 406.3 1.98x 288 5
  All Options Enabled 414.3 2.01x 320 6
Literal List Construction [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Baseline (None) 1.059 1.00x 0 0
  Cost Tracking 3.712 3.51x 0 0
  Memory Tracking (Sample = 1) 31.19 29.45x 0 0
  Memory Tracking (Sample = 5) 31.08 29.35x 0 0
  State Tracing 20.58 19.43x 0 0
  Cost + Memory Tracking 32.26 30.46x 0 0
  Cost Tracking + State Tracing 21.69 20.48x 0 0
  Memory Tracking + State Tracing 46.93 44.32x 0 0
  All Options Enabled 48.44 45.74x 0 0
Map Comprehension (10 elements) a.map(x, x * 2) Baseline (None) 3,074.0 1.00x 2,315 64
  Cost Tracking 3,661.0 1.19x 2,956 84
  Memory Tracking (Sample = 1) 5,481.0 1.78x 2,316 64
  Memory Tracking (Sample = 5) 4,961.0 1.61x 2,316 64
  State Tracing 4,045.0 1.32x 2,315 64
  Cost + Memory Tracking 6,163.0 2.00x 2,958 84
  Cost Tracking + State Tracing 4,712.0 1.53x 2,956 84
  Memory Tracking + State Tracing 6,390.0 2.08x 2,316 64
  All Options Enabled 7,073.0 2.30x 2,958 84
Nested Comprehension (10 elements) a.map(x, [x, x]).filter(...) Baseline (None) 7,397.0 1.00x 5,980 156
  Cost Tracking 8,610.0 1.16x 7,103 196
  Memory Tracking (Sample = 1) 14,447.0 1.95x 5,983 156
  Memory Tracking (Sample = 5) 12,828.0 1.73x 5,983 156
  State Tracing 10,443.0 1.41x 5,980 156
  Cost + Memory Tracking 15,533.0 2.10x 7,106 196
  Cost Tracking + State Tracing 11,847.0 1.60x 7,103 196
  Memory Tracking + State Tracing 16,818.0 2.27x 5,983 156
  All Options Enabled 20,439.0 2.76x 7,106 196
Proto Field Access msg.single_int64 + msg.single_int32 Baseline (None) 91.05 1.00x 0 0
  Cost Tracking 129.6 1.42x 32 1
  Memory Tracking (Sample = 1) 167.5 1.84x 0 0
  Memory Tracking (Sample = 5) 173.7 1.91x 0 0
  State Tracing 179.0 1.97x 0 0
  Cost + Memory Tracking 220.4 2.42x 32 1
  Cost Tracking + State Tracing 217.5 2.39x 32 1
  Memory Tracking + State Tracing 215.6 2.37x 0 0
  All Options Enabled 269.9 2.96x 32 1
Proto Repeated Comprehension (10 elements) msg.repeated_int64.map(...) Baseline (None) 3,198.0 1.00x 2,275 55
  Cost Tracking 3,766.0 1.18x 2,916 75
  Memory Tracking (Sample = 1) 6,093.0 1.91x 2,605 67
  Memory Tracking (Sample = 5) 5,415.0 1.69x 2,605 67
  State Tracing 4,090.0 1.28x 2,363 57
  Cost + Memory Tracking 6,628.0 2.07x 3,246 87
  Cost Tracking + State Tracing 4,786.0 1.50x 3,004 77
  Memory Tracking + State Tracing 6,992.0 2.19x 2,605 67
  All Options Enabled 7,700.0 2.41x 3,246 87

@TristonianJones
TristonianJones force-pushed the peak-memory-limits branch 2 times, most recently from 5ddc84b to 303d40a Compare August 21, 2026 02: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.

1 participant