New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: statically initialize compute-only data #18663
Comments
this kind of feature is very useful to create DoS attacks on the compiler.
Just use //go:generate to write the table as a static data instead.
Then the table only needs to be computed once, not every time the package
is compiled.
|
Yea, It's only worth doing if the compiler has a built-in bound on how long it would execute initialization code for. There's no way for it to know if the function halts. |
On Sat, Jan 14, 2017 at 11:47 PM, Joe Tsai ***@***.***> wrote:
this kind of feature is very useful to create DoS attacks on the compiler.
Yea, It's only worth doing if the compiler has a built-in bound on how
long it would execute initialization code for. There's no way for it to
know if the function halts.
Any time bound will introduce non-determinism to the compiler output.
e.g. a package compiled on slower machine won't have static initialization,
whereas on a faster machine, it will.
If we use a step based bound, how do we determine the bound?
What's wrong with using go:generate to generate the static data once
instead of wasting energy generating it every time the package is compiled?
I think this kind of compiler "feature" is on a very slippy road. Soon
people will ask for more and more function to be precomputed by the
compiler.
|
Some challenges that I run into:
That's a pretty fair argument against doing this in the compiler. I'm closing this. |
Consider the LUT:
This could represented with the compute-only function:
For functions that are compute only at initialization, we could consider pre-computing their value at compilation time and statically assigning the resulting in the compiled binary (assuming the space-complexity is a better trade-off compared to the time-complexity).
While the above example is somewhat trivial, it is helpful for more complex LUTs. For example, this commit 5c78589 removed a more complex LUT for huffman decoding and perform the LUT computation at runtime. It was annoying keeping two separate huffman decoder implementations in sync along with using code-generation to create the LUT.
It would have been nice to just do:
The text was updated successfully, but these errors were encountered: