symforce
symforce copied to clipboard
Add `output_symbols` arg to codegen as performance mitigation
For complex expressions, the calculation of Codegen.output_symbols can grow quite large (encroaching on a minute or more). In some cases, the value of output_symbols can be specified externally. For example:
- The user may have a list of
output_symbolsreadily available at the callsite (frequently it matches the input symbol set exactly). - The
output_symbolscan be determined from anotherCodegenobject, for example in most (though not all) cases the following can work:
cg = Codegen(...)
cg_factor = cg.with_linearization(output_symbols=cg.output_symbols) # avoid recomputation
Ideally free_symbols would be faster, but this is a mitigation/workaround that can offer worthwhile savings in some cases.
This change adds an optional argument to the various constructors of Codegen so that the user can optionally provide the symbols themselves, and avoid an expensive computation.