-
Notifications
You must be signed in to change notification settings - Fork 124
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
RUM-6263 Trigger based approach #2074
base: performance_improvements
Are you sure you want to change the base?
RUM-6263 Trigger based approach #2074
Conversation
Datadog ReportBranch report: ❌ 1 Failed (0 Known Flaky), 3236 Passed, 0 Skipped, 1m 54.38s Total Time ❌ Failed Tests (1)
🔻 Code Coverage Decreases vs Default Branch (1)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great optimization idea 👍 💯 . I left few feedbacks, but most importantly a change request to offload the main thread from unnecessary tasks.
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
ce52eaa
to
2c0baea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 I have left some suggestions and a change-request regard thread safety
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
stopRecording() | ||
} catch { | ||
telemetry.error("[SR] Failed to take snapshot", error: error) | ||
queue.run { [weak self] in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/question We can assume we are already on the main thread, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this runs async job on main thread
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the captureNextRecord
is called by triggers from the main thread, so I wonder why we jump on the main thread again?
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
private var shouldSkipFrame: Bool { | ||
return dateProvider.now.timeIntervalSince(lastFrameTimestamp ?? .distantPast) < Constants.throttingRate | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/suggestion We could have a Debouncer
object that could take care of this, similar to the future TimeBank
, WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally - but for now I'd suggest merging this as is - and refactor once we have timebank in place. It will shed some more slight on our approach of unit testing this
Addressed all the requested changes, and did some extra tests (internal). |
What and why?
This PR changes the default behaviour of the SR recorder from scheduler to trigger based approach. Significantly reducing the SR footprint on idle.
How?
It's achieved by introducing
RecordingTrigger
which is responsible for subscribing to two events:UIView.layoutSubviews
andUIApplication.sendEvent
using obj-c swizzling. Trigger takes a weak dependency on the recording coordinator to start/stop it, as well as invoke captureNextRecord.Those events happen frequently (every touch interaction and each view's layout change), they are throttled for 100ms (which matches scheduler capture frequency).
Below you can find screenshots from the basic Xcode profiler showcasing CPU usage for similar scenario (go through checkout and stay idle on dashboard):
Before
After
Review checklist