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

batched transform #421

Merged
merged 3 commits into from
Apr 12, 2023
Merged

batched transform #421

merged 3 commits into from
Apr 12, 2023

Conversation

ijsnow
Copy link
Contributor

@ijsnow ijsnow commented Mar 2, 2023

Description of the change

Add a transform that applies each transform with a single traverse of each object rather than traversing an object for each transform. The hope is that this will result in less CPU usage since the number of nodes in an object will almost always be larger than the number of transforms and in the case that its not true, performance difference will be negligible.

This is an opt in feature with the batch_transforms field on the settings object, but all tests pass when using the BatchedTransform manually.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Shortcut stories and GitHub issues (delete irrelevant)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

@danielmorell
Copy link
Collaborator

This is related to #412.

@ijsnow
Copy link
Contributor Author

ijsnow commented Mar 2, 2023

Do we care about the depth of a transformed node changing? Only asking because the existing tests pass using the batched transform. I wrote a test case that isn't supported by this change.

def test_switching_depth(self):
    class BoxedNumberTransformer(Transform):
        def transform_number(self, o, key=None):
            return {"num": o}

    class NumberToStringTransformer(Transform):
        def transform_number(self, o, key=None):
            return str(o)

    input = ("hello", {"there": 0})

    got = transform(
        input,
        [BoxedNumberTransformer(), NumberToStringTransformer()],
        batch_transforms=True,
    )

    self.assertEqual(got, ("hello", {"there": {"num": "0"}}))

I'm trying to get a nested traverse call to work but its seeming a little complicated.

@shortcut-integration
Copy link

This pull request has been linked to Shortcut Story #123195: pyrollbar: resource usage problems.

@mudetroit
Copy link

Do we care about the depth of a transformed node changing? Only asking because the existing tests pass using the batched transform. I wrote a test case that isn't supported by this change.

I feel like this is probably okay, but interested on @danielmorell's take on it. I feel like the behavior shown is what I would actually expect but perhaps I am wrong.

@danielmorell
Copy link
Collaborator

danielmorell commented Mar 6, 2023

Do we care about the depth of a transformed node changing? Only asking because the existing tests pass using the batched transform. I wrote a test case that isn't supported by this change.

@ijsnow If I understand correctly, the test you show is failing with the changes in this PR?

@danielmorell
Copy link
Collaborator

I was able to do some profiling and performance testing. Initially this does not look a lot different from the numbers I was seeing before. but I need to make sure that I'm not messing it up somehow.

rollbar/lib/transforms/__init__.py Show resolved Hide resolved
rollbar/lib/traverse.py Show resolved Hide resolved
rollbar/lib/transforms/batched.py Show resolved Hide resolved
@ijsnow
Copy link
Contributor Author

ijsnow commented Mar 8, 2023

@danielmorell

@ijsnow If I understand correctly, the test you show is failing with the changes in this PR?

Yes and it looks like a test that should pass, however if I ensure that the change is used by all usages in the tests, all the existing tests pass, which is the only reason I'm asking if it is intended to be supported.

Do we have any way of knowing how many custom transforms are in use in the wild? I'm giving it another quick pass to try to get that test to work but since its behind a flag in the settings maybe we could just document that caveat, if it indeed does help with performance.

Copy link
Collaborator

@danielmorell danielmorell left a comment

Choose a reason for hiding this comment

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

👍

@danielmorell danielmorell merged commit 674d653 into master Apr 12, 2023
@danielmorell danielmorell deleted the batched-transform branch April 12, 2023 10:53
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.

notifier isn't sending a "platform" param... should it be "python"?
3 participants