[BEAM-3612] Add a benchmark for method invocation methods. #6893
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.
With the Go SDK's necessary default use of reflection to achieve more idiomatic user code, it's up to the framework to reduce this overhead as much as possible. This benchmark illustrates the various methods available to the Go SDK and informs work I've been doing on [BEAM-3612].
Having properly generated type assertion shims at present represents a reduction of around ~400ns per function invocation. As mentioned in the JIRA, I've got a tool I've been working on to make generating these shims easier.
Further, this reveals there's a way to change how we handle method invocation which is relevant for Structural DoFns. The way we use a reflect.Value.Interface() call to get to back to an indirect interface{} version of the method, we typically go through the "Implicit Receiver" route, so that the receiver we're operating on (the Structural DoFn with the associated state) is implicitly cached and instated by the reflection code when we call it. This adds ~180ns overhead (on my machine) compared to the the Explicit Receiver version.
The tricky part here is that moving to Explicit Receivers requires a minor overhaul through the beam function handling code, to properly mark the receiver parameter for the type checking phase. This is better accomplished after we have tools to re-generate type assertion shims for the SDK, if we're doing it at all.
Finally, by having arity Explicit invocation of the shims reduces overhead by another 30ns. This is probably something that can be generated one off (with the above concession to the Explicit Receiver approach) to get a base set of combinatorial values. However, the extra overhead of a arity specialized invoker might be more than the 30ns cost of allocating & extracting the values from the slice, so this should be more specifically benchmarked in context of invoking for ParDos.
Follow this checklist to help us incorporate your contribution quickly and easily:
[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.It will help us expedite review of your Pull Request if you tag someone (e.g.
@username
) to look at it.Post-Commit Tests Status (on master branch)