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

Simplify Analytics.MultiTracker 👁 #229

Merged
merged 1 commit into from
Apr 6, 2021

Conversation

p4checo
Copy link
Member

@p4checo p4checo commented Apr 4, 2021

Checklist

Motivation and Context

While our Analytics.MultiTracker was implemented to be dynamically configured by allowing registering/unregistering sub trackers, in reality this didn't bring much benefit (or at all) as from our experience the tracker is typically configured once during app startup. To allow this dynamism while being thread safe, it resorted to synchronization primitives (i.e. Atomic) on the state, which in practice causes one lock/unlock per track call (trackers). This is obviously a very high price to pay when we consider that the dynamism it allows is rarely used. So, this dynamism has been removed in favor of configuring the tracker once on init, passing in the sub-trackers to use.

Additionally, some some minor improvements were made to Analytics related types.

Description

  • Make Analytics.MultiTracker have its sub-trackers be configured on init, avoiding complexity and contention due to handling concurrent operations.

  • Remove ID from AnalyticsTracker, as it was used mostly to keep track of registered trackers.

  • Add eraseToAnyAnalyticsRracker() helper in AnalyticsTracker to facilitate type erasing trackers to passinto Analytics.MultiTrackers.

  • Add _wrapped helper property in AnyAnalyticsTracker to hold a reference to the wrapped tracker instance.

While our `Analytics.MultiTracker` was implemented to be dynamically
configured by allowing registering/unregistering sub trackers, in
reality this didn't bring much benefit (or at all) as from our
experience the tracker is typically configured once during app
startup. To allow this dynamism while being thread safe, it resorted to
synchronization primitives (i.e. `Atomic`) on the state, which in
practice causes one lock/unlock per track call (trackers). This
is obviously a very high price to pay when we consider that the
dynamism it allows is rarely used. So, this dynamism has been removed
in favor of configuring the tracker once on `init`, passing in the
sub-trackers to use.

Additionally, some some minor improvements were made to Analytics
related types.

## Changes

- Make `Analytics.MultiTracker` have its sub-trackers be configured on
`init`, avoiding complexity and contention due to handling concurrent
operations.

- Remove `ID` from `AnalyticsTracker`, as it was used mostly to keep
track of registered trackers.

- Add `eraseToAnyAnalyticsRracker()` helper in `AnalyticsTracker` to
facilitate type erasing trackers to passinto `Analytics.MultiTracker`s.

- Add `_wrapped` helper property in `AnyAnalyticsTracker` to hold
a reference to the wrapped tracker instance.
@codecov
Copy link

codecov bot commented Apr 4, 2021

Codecov Report

Merging #229 (e5d6a77) into master (945dfc8) will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #229      +/-   ##
==========================================
- Coverage   94.98%   94.95%   -0.03%     
==========================================
  Files          97       97              
  Lines        3267     3252      -15     
==========================================
- Hits         3103     3088      -15     
  Misses        164      164              
Impacted Files Coverage Δ
...es/Analytics/Trackers/Analytics+MultiTracker.swift 100.00% <100.00%> (ø)
Sources/Analytics/Trackers/AnalyticsTracker.swift 100.00% <100.00%> (ø)
...urces/Analytics/Trackers/AnyAnalyticsTracker.swift 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 945dfc8...e5d6a77. Read the comment docs.

@p4checo p4checo merged commit 932e082 into master Apr 6, 2021
@p4checo p4checo deleted the simplify-analytics-multi-tracker branch April 6, 2021 16:53
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.

5 participants