-
Notifications
You must be signed in to change notification settings - Fork 134
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: develop
Are you sure you want to change the base?
Conversation
Datadog ReportBranch report: ❌ 1 Failed (1 Known Flaky), 192 Passed, 3147 Skipped, 17.27s Total duration (1m 47.66s time saved) ❌ Failed Tests (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
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
Addressed all the requested changes, and did some extra tests (internal). |
2ada16b
to
dd947ad
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 great! Thanks for the changes 🙏
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.
Awesome work! And this CPU improvement is very welcome! 👏
General question: Since we're fully transitioning to swizzling for SR recording, should we consider updating the documentation to add warnings for customers? E.g., potential conflicts with other SDKs or their own code that might also be using swizzling.
DatadogSessionReplay/Tests/Recorder/RecordingCoordinatorTests.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Tests/Recorder/RecordingCoordinatorTests.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
198422b
to
ec17e2f
Compare
9019d8d
to
3d6060e
Compare
3d6060e
to
3bbdf54
Compare
9b3a246
to
95157bc
Compare
We decided to slightly revamp the approach. Closing this one for the time being. |
Just noticed I need to add tests for the new swizzlers. On it. Will reopen when done. |
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.
It looks good, I like the split between RecordingCoordinator
and RecordingTrigger
👍
What's less clear to me is the various method that we swizzle, it seems empirical and I'm not sure why we need so many. For example, CALayer.draw
seems sufficient to catch all rendering, then why do we need CALayer.setNeedsDisplay
and UIView.layoutSubviews
? In this context, UIViewController.viewDidAppear
seems redundant.
Also, I think we should let the previous swizzled implementation execute and then notify to coordinator. To not delay the CoreGraphics rendering and record the new layout.
I also left some minor question/nit but these 2 points are the most important.
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Utilities/Schedulers/Scheduler.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
DatadogSessionReplay/Sources/Recorder/RecordingCoordinator.swift
Outdated
Show resolved
Hide resolved
...sts/IntegrationScenarios/Scenarios/SessionReplay/SRMultipleViewsRecordingScenarioTests.swift
Show resolved
Hide resolved
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.
Lets address the comments above.
…cording # Conflicts: # DatadogSessionReplay/Sources/Feature/SessionReplayFeature.swift
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
![Screenshot 2024-10-09 at 13 15 16](https://private-user-images.githubusercontent.com/6953112/374933060-9f892bb5-da38-47f3-a86d-7a8d77b22ebc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzI1MjksIm5iZiI6MTczOTE3MjIyOSwicGF0aCI6Ii82OTUzMTEyLzM3NDkzMzA2MC05Zjg5MmJiNS1kYTM4LTQ3ZjMtYTg2ZC03YThkNzdiMjJlYmMucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMDcyMzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YzFlMDQxNmM5ZTdiNzg1YTRhYTBiMzQ1YzY2MTFlOTFhZThjMDRjYzgyM2I4YjI5ZTAyOWE0YmRhYzljZjA2OSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.FZGoup_M-fV6VF9p03BC0C_WKqFh-y8dgj2lP_XeJhw)
After
![Screenshot 2024-10-09 at 13 09 47](https://private-user-images.githubusercontent.com/6953112/374933084-ad0eb3dd-cdac-40af-b616-b6262e509579.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxNzI1MjksIm5iZiI6MTczOTE3MjIyOSwicGF0aCI6Ii82OTUzMTEyLzM3NDkzMzA4NC1hZDBlYjNkZC1jZGFjLTQwYWYtYjYxNi1iNjI2MmU1MDk1NzkucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxMCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTBUMDcyMzQ5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9M2NhODg5YjhlNWFkMDFjZDhmYmU3NzM4NjhiYzkwOTQ2NGJlY2FlYmEwZWEzZTMyOWM2NDY0ZTU3NmEwNjI2NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.2ea40pByzMoZPGHX7xVvHvINqQkDLQUSBY3TkrwXW-A)
Review checklist