-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make make_scalar_function() result candidate for inlining, by removing the Arc
#12477
Make make_scalar_function() result candidate for inlining, by removing the Arc
#12477
Conversation
`make_scalar_function` serves as a template to implement functions, abstracting away processing of scalar values. While it's recommended to implement `ScalarUDFImpl` directly, a few functions still use the `make_scalar_function` helper, perhaps because it reduces code verbosity. While `make_scalar_function` is a template function, it's not eligible for effective inlining because of the `Arc<Fn>` return type. This commit removes `Arc` and unlocks inlining. The change impact was verified manually using `cargo rustc -p datafusion-functions-nested -- --emit asm -C opt-level=2` and comparing the generated for `ArrayDistance::invoke` exemplary function that uses `make_scalar_function`. Only after the changes can `ArrayDistance::invoke` call the `array_distance_inner` directly. The change saves some small overhead on each invocation of a UDF, but doesn't improve per-row performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me -- thank you @findepi
What do you think about removing ScalarFunctionImplementation
entirely? Or is it still important to have a typedef around the Arc
🤔
Arc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks @findepi
I think there some more usages of this type |
FWIW with
|
make_scalar_function
serves as a template to implement functions, abstracting away processing of scalar values. While it's recommended to implementScalarUDFImpl
directly, a few functions still use themake_scalar_function
helper, perhaps because it reduces code verbosity.While
make_scalar_function
is a template function, it's not eligible for effective inlining because of theArc<Fn>
return type.This commit removes
Arc
and unlocks inlining. The change impact wasverified manually using
cargo rustc -p datafusion-functions-nested -- --emit asm -C opt-level=2
and comparing the generated forArrayDistance::invoke
exemplary function that usesmake_scalar_function
. Only after the changes canArrayDistance::invoke
call thearray_distance_inner
directly.The change saves some small overhead on each invocation of a UDF, but doesn't improve per-row performance.