interp: make the timeout recoverable, per package initializer - #5587
interp: make the timeout recoverable, per package initializer#55870pcom wants to merge 1 commit into
Conversation
|
Previously #2384 |
A package initializer that cannot be computed at compile time — crypto AES key expansion, secp256k1 table setup — would run the interpreter out of its budget and fail the BUILD. The only recourse was to raise the timeout for everything, which just moves the cliff. The timeout is now an ordinary recoverable error: the initializer that exceeded it reverts to a runtime call, exactly as it would on native Go, and the build continues. Each initializer also gets its own budget rather than sharing one, so a single expensive one no longer starves the remaining packages of precomputation they CAN do. Under -debug it says which package timed out and after how long, because "this init is now happening at startup instead of compile time" is a performance fact worth being able to see.
5b23570 to
9be25f9
Compare
|
Thanks for the pointer — I had not seen #2384, and reading it changes what I think this PR should be. First, an apology: the branch was carrying things it should not. Rebased on dev, it was reverting real upstream work — the On the substance. The objection that closed #2384 applies to this PR too, and I should say so plainly rather than let it be rediscovered. @aykevl's point was that timing out makes builds non-reproducible, and @niaow's was the same. This change arguably makes that worse, not better: today the wall clock decides whether the build fails, which is at least loud. With this, the wall clock decides what the binary contains — a fast machine precomputes an initializer, a loaded one defers it to runtime startup. Same source, two different outputs, silently. That is exactly what was rejected. The fix you and @niaow converged on there was a counter, and
Here is that example, which is what prompted this. Two initializers reliably exhaust a 3-minute budget: AES key expansion in If that is an interp bug worth fixing, then fixing it is better than any budget and this PR should be closed. If it is simply more computation than interp should be asked to do at build time, then the counter version is the smallest honest change and I will send it. Your call — I would rather not re-litigate #2384 by accident. |
A package initializer that cannot be computed at compile time — crypto AES key expansion, secp256k1 table setup — runs the interpreter out of its budget and fails the build:
The only recourse today is raising
-interp-timeoutfor everything, which moves the cliff rather than removing it, and slows every other build to accommodate one package.This makes the timeout an ordinary recoverable error. The initializer that exceeded its budget reverts to a runtime call — exactly what would happen on native Go — and the build continues.
errTimeoutjoins the existing set of recoverable errors (errLoopUnrolled,errLoopTooLong,errInvalidPtrToIntSize), so it takes the same path those already do.Each initializer also gets its own budget rather than sharing one clock across the whole run. Previously a single expensive initializer could consume the budget and leave the packages after it with no time for precomputation they could have done.
Under
-debugit reports which package timed out and after how long, since "this init now happens at startup instead of at compile time" is a performance fact worth being able to see.Verified:
go test ./interp/passes, and a program with an initializer heavy enough to exhaust the budget now builds and runs (printing the value its init computed) where it previously failed the build.