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

🐛 [RUM-8353] Throttle view context update #3314

Merged
merged 4 commits into from
Feb 4, 2025

Conversation

cy-moi
Copy link
Contributor

@cy-moi cy-moi commented Feb 3, 2025

Motivation

Updating of view context automatically triggers view updates, which could trigger excessive requests in edge cases. We should throttle view updates while maintaining current view context update behavior.

Changes

Added a new LifeCycleEvent type so we can update the view context for in viewHistory immediately
Use scheduleViewUpdate to throttle the view updates

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

@cy-moi
Copy link
Contributor Author

cy-moi commented Feb 3, 2025

/to-staging

@cy-moi cy-moi marked this pull request as ready for review February 3, 2025 10:59
@cy-moi cy-moi requested a review from a team as a code owner February 3, 2025 10:59
@dd-devflow
Copy link
Contributor

dd-devflow bot commented Feb 3, 2025

Devflow running: /to-staging

View all feedbacks in Devflow UI.


2025-02-03 10:59:41 UTC ℹ️ Branch Integration: starting soon, median merge time is 0s

Commit a5e9c230bb will soon be integrated into staging-06.


2025-02-03 11:11:05 UTC ℹ️ Branch Integration: This commit was successfully integrated

Commit a5e9c230bb has been merged into staging-06 in merge commit 5e6fa9a836.

Check out the triggered pipeline on Gitlab 🦊

If you need to revert this integration, you can use the following command: /code revert-integration -b staging-06

dd-mergequeue bot added a commit that referenced this pull request Feb 3, 2025
@dd-devflow dd-devflow bot added the staging-06 label Feb 3, 2025
@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.59%. Comparing base (46cc11a) to head (4ac34a3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3314   +/-   ##
=======================================
  Coverage   93.58%   93.59%           
=======================================
  Files         291      291           
  Lines        7691     7703   +12     
  Branches     1751     1751           
=======================================
+ Hits         7198     7210   +12     
  Misses        493      493           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cy-moi cy-moi force-pushed the congyao/throttle-view-context-update branch from 094d837 to c883c7e Compare February 3, 2025 12:27
Copy link

cit-pr-commenter bot commented Feb 3, 2025

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum 146.77 KiB 147.05 KiB 279 B +0.19%
Logs 51.19 KiB 51.19 KiB 0 B 0.00%
Rum Slim 105.52 KiB 105.77 KiB 254 B +0.24%
Worker 24.50 KiB 24.50 KiB 0 B 0.00%
🚀 CPU Performance
Action Name Base Average Cpu Time (ms) Local Average Cpu Time (ms) 𝚫
addglobalcontext 0.002 0.002 -0.000
addaction 0.031 0.037 0.005
addtiming 0.006 0.001 -0.005
adderror 0.028 0.051 0.022
startstopsessionreplayrecording 0.001 0.012 0.011
startview 0.007 0.391 0.384
logmessage 0.025 0.021 -0.004
🧠 Memory Performance
Action Name Base Consumption Memory (bytes) Local Consumption Memory (bytes) 𝚫 (bytes)
addglobalcontext 28.15 KiB 27.95 KiB -203 B
addaction 57.12 KiB 56.26 KiB -874 B
addtiming 27.30 KiB 26.22 KiB -1108 B
adderror 62.00 KiB 58.38 KiB -3704 B
startstopsessionreplayrecording 25.50 KiB 25.37 KiB -128 B
startview 415.29 KiB 422.12 KiB 6.83 KiB
logmessage 60.20 KiB 62.86 KiB 2.65 KiB

🔗 RealWorld


// View context update should always be throttled
contextManager.changeObservable.subscribe(() => {
lifeCycle.notify(LifeCycleEventType.BEFORE_VIEW_UPDATED, {
Copy link
Collaborator

@amortemousque amortemousque Feb 3, 2025

Choose a reason for hiding this comment

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

💬 suggestion: ‏I would expect BEFORE_VIEW_UPDATE to be called each time scheduleViewUpdate or triggerViewUpdate are called. Something like

  const { throttled, cancel: cancelScheduleViewUpdate } = throttle(triggerViewUpdate, THROTTLE_VIEW_UPDATE_PERIOD, {
    leading: false,
  })

  const scheduleViewUpdate = () => {
    triggerBeforeViewUpdate()
    throttled()
  }

 function triggerViewUpdate() {
    triggerBeforeViewUpdate()
    ...

@@ -67,6 +67,13 @@ export interface ViewCreatedEvent {
startClocks: ClocksState
}

export interface ViewContextEvent {
Copy link
Collaborator

Choose a reason for hiding this comment

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

💬 suggestion:

Suggested change
export interface ViewContextEvent {
export interface BeforeViewUpdateEvent {

@cy-moi cy-moi force-pushed the congyao/throttle-view-context-update branch from 2a4ad53 to 030c7d1 Compare February 3, 2025 18:05
@@ -924,6 +924,8 @@ describe('view event count', () => {
const { getViewUpdate, setViewContext } = viewTest

setViewContext({ foo: 'bar' })
clock.tick(3000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

💬 suggestion: ‏ Use THROTTLE_VIEW_UPDATE_PERIOD so we know where this value comes from and why we need it

@cy-moi cy-moi force-pushed the congyao/throttle-view-context-update branch from 030c7d1 to c883c7e Compare February 4, 2025 10:08
@cy-moi cy-moi merged commit 8a7de5a into main Feb 4, 2025
19 checks passed
@cy-moi cy-moi deleted the congyao/throttle-view-context-update branch February 4, 2025 12:20
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.

4 participants