-
Notifications
You must be signed in to change notification settings - Fork 111
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
Remove unused let-bindings in compiled RHS action functions #383
Comments
I've created a preliminary PR for this at #384. Please don't merge it yet though. Further items to address:
|
It sounds like a nasty pattern in the RHS to have macros result in bindings used like that. If someone is doing that, I think having to do the workaround would be appropriate. Doing a bunch of (crazy) operations inline should be considered an anti-pattern. It also makes it more difficult to do optimizations like done here.
Do you have any sort of rough numbers on that? I'm curious what you've seen. |
Examples like this produce 1023 byte class .class files on my machine, using the *compile-files* option to force dumping of the generated bytecode to disk.
Examples like the following produce 2444 byte .class files on my machine.
Getting consistent eval time comparisons is proving difficult, but it doesn't seem likely that simply removing code that doesn't interact with anything else in the body being evaluated would increase the time to eval the remaining code. In any case reducing the bytecode size is beneficial in itself. I've merged the PR. I don't think there is anything left to do here but we can reopen if others disagree. |
Take the following rule:
When we create a session with this rule and inspect the compiled RHS function, noting that the the unevaluated expression is added as metadata to the ProductionNode for later use in durability :
we retrieve the following:
Note that a let-binding for ?windspeed is created even though it is not used in the user's RHS code. It does not appear that the code which creates these RHS let-binding makes any attempt to determine what bindings are used in the RHS. As a result unnecessary bindings are created, consuming time to create at runtime and increasing the amount of Clojure code evaluated at session creation time, thus likely increasing total session compilation time.
In order to fix this we can apply a similar fix to what was done in #180 for let bindings of fields that aren't actually used in constraints. We'd basically just walk the user's RHS code and detect what bindings are present in it. Since the bindings have to be literals in the code (rather than in outside user functions called by the RHS, where they aren't resolvable by Clojure's compiler) this can be done safely.
The text was updated successfully, but these errors were encountered: