-
Notifications
You must be signed in to change notification settings - Fork 15
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
Generated code is highly redundant #53
Comments
After literally months, I finally thought of an "obvious" solution to this problem. This problem can be solved by managing a "stack" of actions and nodes that you need to go to. For example, imagine an edge with actions
, where all action blocks
But... that's literally how function calls work! 😅 Well, almost. My proposed solution is to wrap all actions in an anonymous function. The edge's code is then
This is slightly more inefficient because after Needs to be benchmarked, though. All these extra branches could really mess up performance. |
I doubt I can actually implement this. Instead, I'll just improve the docs to explain that I recommend the actions are function calls. |
I got a new idea on how to implement this. The idea is to outline code by wrapping it in julia> function foo()
function bar()
y += x
end
x = 1
y = 1
bar()
y
end;
julia> foo()
2 This works by default because inner functions are closures in Julia. |
I'm glad you're still thinking about this, because I have zero concept of the implications 😅 Does it help at all to use other kinds of closures - anonymous functions, |
I don't think that makes a difference. I'm going to try implementing this at some point and see the performance impact. |
Currently, in
generate_exec_code
, with :goto-generators, the expression bound to each action is NOT spliced into the generated code once. Instead, it is spliced into the generated code once for every edge in the FSM it appears on.This is due to simplicity. Now, every edge generates its own little code snippet. For example, if the N'th edge leading to state X contains the action
:foo
with the Julia codedo_foo()
, the generated code will beThe problem, of course, is that the action
foo
can be present on many edges. So instead of using the gotos to go to the SAME code section withdo_foo()
,do_foo()
is spliced in multiple times leading to huge codegen.Worse, the codegen potentially scales with the number of states squared.
Here is a MWE that makes the codegen blow up
It can get much worse. Setting LETTERS to e.g.
'a':'z'
will cause each of the 26 actions to be duplicated 26^2 times, leading to 5.4 MiB of native code.And here is a counter of how many times each action is multiplied in the code in FASTX.jl's FASTA machine:
We really, really should fix this.
The text was updated successfully, but these errors were encountered: