nestedBindExpr produces an exponentially amplified value through nested cel.bind calls: cel.bind(a0, [0,1,2,3,4,5,6,7,8,9], cel.bind(a1, [a0,a0,a0,a0,a0,a0,a0,a0,a0,a0], ... cel.bind(aN, [aN-1 x10], aN == aN))) Each level is physically a 10-element list of references to the level below, s
(levels int)
| 297 | // Each level is physically a 10-element list of references to the level below, so the |
| 298 | // logical element count grows by 10x per level while the physical allocation stays small. |
| 299 | func nestedBindExpr(levels int) string { |
| 300 | expr := fmt.Sprintf("a%d == a%d", levels, levels) |
| 301 | for i := levels; i >= 1; i-- { |
| 302 | refs := strings.TrimSuffix(strings.Repeat(fmt.Sprintf("a%d,", i-1), 10), ",") |
| 303 | expr = fmt.Sprintf("cel.bind(a%d, [%s], %s)", i, refs, expr) |
| 304 | } |
| 305 | return fmt.Sprintf("cel.bind(a0, [0,1,2,3,4,5,6,7,8,9], %s)", expr) |
| 306 | } |
| 307 | |
| 308 | func TestBindingsMemoryPeakAmplification(t *testing.T) { |
| 309 | // The tracked peak reflects the full logical element count of the largest bound value: |
no outgoing calls
no test coverage detected