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

Avoid expensive set construction in Config constructor #1289

Merged
merged 1 commit into from
Jun 25, 2021

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Jun 24, 2021

Goal

Initializing Configuration was taking more time than it needed to due to the construction of some unnecessary sets. The toSet() implementation in Kotlin seems like it can be particularly slow in some circumstances, as it constructs a LinkedHashSet. This is unnecessary for the purposes of Configuration.

Changeset

  • Avoided creation of unnecessary field for redactedKeys
  • Initialized plugins with a HashSet rather than a LinkedHashSet
  • Set enabledBreadcrumbTypes to null rather than constructing a set - this has the same behaviour as setting all the values

Without these optimizations Configuration took ~38ms to initialize, whereas with them it took ~9ms. It's worth noting that this only seems to be on a cold start, suggesting that there is some one-off work required when the JVM is initialized. Therefore the differences don't show up in the automated benchmarks and have been manually profiled instead.

before_changes

after_changes

Testing

Relied on existing test coverage.

@fractalwrench fractalwrench force-pushed the optimize-config-init branch from 4d85467 to ecab6d8 Compare June 24, 2021 10:56
@fractalwrench fractalwrench marked this pull request as ready for review June 24, 2021 11:13
@fractalwrench fractalwrench requested a review from lemnik June 24, 2021 11:13
@bugsnagbot
Copy link
Collaborator

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1511.91 1408.8
arm64_v8a 402.11 295.61
armeabi 385.72 279.22
armeabi_v7a 365.25 262.85
x86 443.05 336.55
x86_64 422.58 320.18

Generated by 🚫 Danger

Copy link
Contributor

@lemnik lemnik left a comment

Choose a reason for hiding this comment

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

LGTM

@fractalwrench fractalwrench force-pushed the optimize-config-init branch from ecab6d8 to 9d9e326 Compare June 24, 2021 15:52
@fractalwrench fractalwrench force-pushed the optimize-config-init branch from 9d9e326 to b1e1d38 Compare June 25, 2021 08:19
@fractalwrench fractalwrench merged commit b13da15 into next Jun 25, 2021
@fractalwrench fractalwrench deleted the optimize-config-init branch June 25, 2021 09:28
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.

3 participants