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

RUMM-2441 Optimize BaseWireframeMapper#colorAndAlphaAsStringHexa function #1077

Conversation

mariusc83
Copy link
Collaborator

What does this PR do?

We were using the String.format approach to resolve the shape color, alpha values as a hexa string property and this was quite costly in terms of performances. We are changing this relying on the Int.toString(radius) function which is much more faster.

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@mariusc83 mariusc83 requested a review from a team as a code owner October 10, 2022 08:52
@mariusc83 mariusc83 self-assigned this Oct 10, 2022
Comment on lines 24 to 30
val colorAndAlphaAsHexa = (0xffffffff and colorAndAlpha)
.toString(16)
.padStart(8, '0')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you give some details on why this algorithm is more optimized vs the String.format one? Did you benchmark this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I profiled this with the Android Profiler...there is a big difference there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because we are using this function for each tree node...I profiled the whole snapshot function. With the String.format the difference is ~10ms + which is huge.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it'd be nice to add a comment there to make sure we remember why we use a three line code instead of a one liner ;)

@mariusc83 mariusc83 force-pushed the mconstantin/rumm-2441/screen-recorder-optimize-the-color-resolver-function branch 2 times, most recently from 4199cea to b7d11ce Compare October 10, 2022 12:55
@mariusc83 mariusc83 force-pushed the mconstantin/rumm-2441/screen-recorder-optimize-the-color-resolver-function branch from b7d11ce to d752382 Compare October 10, 2022 13:40
Comment on lines +24 to +27
// we are going to use the `Long.toString(radius)` method to produce the hexa
// representation of the color and alpha long value because is much more faster than the
// String.format(..) approach. Based on our benchmarks, because String.format uses regular
// expressions under the hood, this approach is at least 2 times faster.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Great, thanks 👍

@mariusc83 mariusc83 merged commit 3200133 into feature/sdkv2 Oct 11, 2022
@mariusc83 mariusc83 deleted the mconstantin/rumm-2441/screen-recorder-optimize-the-color-resolver-function branch October 11, 2022 11:41
@xgouchet xgouchet added this to the 1.16.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants