Remove Dict{Symbol, Any} for type stability in FunctionOperator
#255
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.
The current implementation of
FunctionOperatorrequires aDict{Symbol,Any}to handle the keyword arguments. This leads to type instabilities and performance decreases, as in the following simple code:master branch
BenchmarkTools.Trial: 10000 samples with 53 evaluations. Range (min … max): 864.434 ns … 104.262 μs ┊ GC (min … max): 0.00% … 98.52% Time (median): 947.340 ns ┊ GC (median): 0.00% Time (mean ± σ): 996.750 ns ± 1.294 μs ┊ GC (mean ± σ): 2.57% ± 2.17% ▃█ ▂▂▃▅▄▃▃▃▅███▄▃▃▃▃▃▃▃▃▄▅▄▄▃▂▂▂▂▂▂▂▂▂▂▂▁▂▁▂▂▂▂▂▂▂▂▂▁▂▂▂▂▂▂▂▂▂▂▂ ▃ 864 ns Histogram: frequency by time 1.34 μs < Memory estimate: 560 bytes, allocs estimate: 7.This PR branch
To manage to fix this issue, I used
NamedTupleinstead ofDict{Symbol, Any}. For this reason, the additionalkwargsare required whenaccepted_kwargsis provided, in order to initialize the types inside theNamedTuple. In principle, theaccepted_kwargscan be directly obtained fromkwargskeys, but I left it for consistency with the other functions.Furthermore, I've extended the methods of the
get_filtered_kwargs, also supportingValtypes foraccepted_kwargs. In this way, the filtering is performed at compile time, otherwise the type of theNamedTuplecannot be inferred. Thus, all the other functions supportingaccepted_kwargswould also supportValtypes, improving performance.