Skip to content
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

[BEAM-37] DoFnReflector: Add invoker interface and generate code #521

Closed
wants to merge 12 commits into from

Conversation

bjchambers
Copy link
Contributor

Be sure to do all of the following to help us incorporate your contribution
quickly and easily:

  • [*] Make sure the PR title is formatted like:
    [BEAM-<Jira issue #>] Description of pull request
  • [*] Make sure tests pass via mvn clean verify. (Even better, enable
    Travis-CI on your fork and ensure the whole test matrix passes).
  • [*] Replace <Jira issue #> in the title with the actual Jira issue
    number, if there is one.
  • [*] If this contribution is large, please file an Apache
    Individual Contributor License Agreement.

The method to call for a DoFnWithContext requires reflection since the
shape of the parameters may change. Doing so in each processElement call
puts this refelection in the hot path.

This PR introduces a DoFnInvoker interface which is bound to a specific
DoFnWithContext and delegates the three important methods (startBundle,
processElement, finishBundle).

It uses byte-buddy to generate a simple trampoline implementation of
the DoFnInvoker class for each type of DoFnWithContext.

This leads to 2-3x better performance in micro-benchmarks of method
dispatching.

@bjchambers
Copy link
Contributor Author

@lukecwik @kennknowles Probably not ready for a full review yet, but please take a look in case there is any high-level feedback.

@@ -429,6 +429,12 @@
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove the above jsr305 dependency, you can probably get rid of the above ignoredUnusedDeclaredDependency config. I have this fix in a branch that isn't yet ready to merge-- perhaps I should get that in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it now in? I am confused by this since we use findbugs annotations all over the place prior to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my findbugs PR is now in, which switches all dependencies to use com.google.code.findbugs:annotations instead of jsr305.

If you still get unused/undeclared dependency errors after switching, run mvn dependecy:tree to see if jsr305 is being brought in transitively; you may need to explicitly exclude it.

@lukecwik
Copy link
Member

Not a big fan of how prepareForProcessing is wired through via isStartBundle flag but can't come up with a cleaner proposal since I think creating a bunch of specialized subclasses will just make it worse then having the one flag. Otherwise I'm happy with the approach, adding any additional methods / changing method invocation should be pretty easy.

@kennknowles
Copy link
Member

Typo in the PR title comes from a typo in the commit subject line.

@@ -449,6 +455,12 @@
</dependency>

<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.4.3</version>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a candidate for versioning in the <dependencyManagement> section.

@kennknowles
Copy link
Member

This is awesome. It is a lot to chew on. I need to learn more about the meaning of various bytebuddy interfaces. Given the tests, I am pretty happy. I'd love even more tests, given the potential fragility and debugging challenges of dropping to bytecode. I will think a bit about what they might be.

@bjchambers bjchambers changed the title [BEAM-37] DoFnReflector: Add inoker interface and generate code [BEAM-37] DoFnReflector: Add invoker interface and generate code Jul 6, 2016
<!-- This dependency is only used for an annotation which doesn't
show up in bytecode, so doesn't show up as used. -->
<ignoredUnusedDeclaredDependencies>
<ignoredUnusedDeclaredDependency>com.google.code.findbugs:findbugs-annotations</ignoredUnusedDeclaredDependency>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix here is, I think, to exclude jsr305 which presumably was pulled in by bytebuddy. Otherwise everyone downstream has trouble with the dependency analysis as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but you should just check the dependency tree to see why this is happening)

Ben Chambers added 10 commits July 14, 2016 14:34
The method to call for a DoFnWithContext requires reflection since the
shape of the parameters may change. Doing so in each processElement call
puts this refelection in the hot path.

This PR introduces a DoFnInvoker interface which is bound to a specific
DoFnWithContext and delegates the three important methods (startBundle,
processElement, finishBundle).

It uses byte-buddy to generate a simple trampoline implementation of
the DoFnInvoker class for each type of DoFnWithContext.

This leads to 2-3x better performance in micro-benchmarks of method
dispatching.
@kennknowles
Copy link
Member

LGTM. Might need build unbreakage from @swegner.

@kennknowles
Copy link
Member

Merging...

@asfgit asfgit closed this in 79c26d9 Jul 15, 2016
@dhalperi
Copy link
Contributor

Typically when we change pom.xml to have new dependencies we need to have a discussion about dependencies & licensing.

  • What new dependencies are added?
  • Are they quality and stable enough to depend on?
  • Are they public or private deps; should they be shaded?
  • Do they all (and all transitive deps) have appropriate licenses?

@bjchambers : Did you have that discussion off-thread and, if not, can we verify that we're doing the right thing in all places?

@bjchambers bjchambers deleted the byte-buddy-dofn branch November 21, 2016 21:41
johnjcasey pushed a commit to johnjcasey/beam that referenced this pull request Feb 8, 2023
johnjcasey pushed a commit to johnjcasey/beam that referenced this pull request Feb 8, 2023
johnjcasey pushed a commit to johnjcasey/beam that referenced this pull request Feb 8, 2023
johnjcasey pushed a commit to johnjcasey/beam that referenced this pull request Feb 8, 2023
pl04351820 pushed a commit to pl04351820/beam that referenced this pull request Dec 20, 2023
* chore: remove googleapis/firestore-dpe from codeowners

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants