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

Optimize metadata implementation by reducing type casts #1277

Merged
merged 2 commits into from
Jun 18, 2021

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Jun 17, 2021

Goal

Bugsnag's stores metadata using a nested ConcurrentHashMap. The implementation uses unnecessary type casts, which resulted in unnecessary calls to TypeIntrinsics.isMutableMap() that added ~1ms for every ~10000 metadata values added.

Changeset

Metadata was previously backed by ConcurrentHashMap<String, Any>. This has been changed to MutableMap<String, MutableMap<String, Any>>.

This more accurately reflects the metadata structure and has allowed for a net reduction in type casts throughout Metadata.kt. This has necessitated the addition of some type casts (mainly to maintain backwards compatibility with method signatures that should not change until the next major version).

Testing

Relied on existing unit test coverage.

The performance impact of this change ended up being fairly minimal - typically TypeIntrinstics executed in <1ms, so its removal has a benefit around that amount. However, this still feels advantageous in that it simplifies the implementation and increases its type safety.

@fractalwrench fractalwrench force-pushed the PLAT-6743/add-metadata-optimization branch from 745ff0d to af6e5c3 Compare June 17, 2021 15:06
@fractalwrench fractalwrench marked this pull request as ready for review June 17, 2021 15:26
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 PLAT-6743/add-metadata-optimization branch from af6e5c3 to a602579 Compare June 18, 2021 08:15
@fractalwrench fractalwrench merged commit d73e028 into next Jun 18, 2021
@fractalwrench fractalwrench deleted the PLAT-6743/add-metadata-optimization branch June 18, 2021 09:51
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.

2 participants