[perf] : cache compiled Lua FunctionProto in RunScript to avoid redundant parse+compile on every call
kind/feature
**What would you like to be added**:
Cache compiled Lua `FunctionProto` in the VM so scripts are parsed and compiled only once instead of on every
`RunScript` call.
Right now `RunScript` calls `l.DoString(script)` every single invocation even though the script never changes
for a given customization. The fix is to compile once, store in a `sync.Map` keyed by script content, and
reuse via `NewFunctionFromProto` + `PCall`. Behavior stays identical.
Benchmarked the isolated parse+compile cost:
| | ns/op | B/op | allocs/op |
|---|---|---|---|
| `DoString` (current) | 108,936 | 63,240 | 393 |
| Cached proto | 1,827 | 2,888 | 10 |
File: `pkg/resourceinterpreter/customized/declarative/luavm/lua.go` :- `RunScript()`
---
**Why is this needed**:
`RunScript` is called on every status event through `ReflectStatus`, `InterpretHealth`, `AggregateStatus` etc.
In large fleets this is continuous unnecessary allocation and GC pressure. The script is immutable so
recompiling it every time is pure waste.
Sub-task of #7596.
1 条评论