Avoid redundant ifs (using generated functions?) #362
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there are some patterns in the code which go along the lines of
(these lines can be be found around here:
TaylorSeries.jl/src/arithmetic.jl
Line 511 in 0585883
I gather such patterns avoid code repetitions, while generally the "cost" of running these
if
s is quite low. Just for the sake of confirming this, I experimented a bit with generated functions, which allow to preserve the specialization for each type while avoiding code repetition, with the advantage of resolving them at compilation time, instead of being checked during run time once per method call. This can become important when handling mixtures ofTaylor1{TaylorN{T}}
in TaylorIntegration, where the number of coefficients can be quite large, and these if's can be checked many times during run time, when it's only necessary to check them at dispatch.Gotten to this point, though, maybe an equally good solution would be to simply separate
Taylor1
andTaylorN
methods for patterns such as above? The latter can be more friendly to develop, and would avoid the use of generated functions, which looks maybe a bit overkill here?So essentially what I'm proposing is to either remove the
if $T == Taylor1 ...
in the way they are now, or keep them by using generated functions, such that performance can improve a bit. Benchmarks I've run with TaylorIntegration on JT integrations show ~5% performance improvement. Not much indeed, but can be meaningful for longer runs.