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

[perf logging] Add timing event when browser tab is hidden #9733

Merged

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented May 4, 2020

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

When dashboard is landed in a hidden browser tab, charts are not fetched until user focus on the browser tab again. See this doc: https://developers.google.com/web/updates/2017/03/background_tabs

When airbnb measure dashboard performance, we count page load time is from navigation start till all charts are loaded and rendered in the dashboard. When user open dashboard in a hidden tab, for example, ctrl+click a dashboard link, dashboard will be open in a new tab, but charts will not be loaded until user focus on this tab, and the whole hidden mode time is counted as dashboard load time.

This PR is to add a timing_event in dashboard perf logging data. It should log the total duration time that dashboard is in the hidden tab.

TEST PLAN

Manual test.

REVIEWERS

@etr2460

@codecov-io
Copy link

codecov-io commented May 4, 2020

Codecov Report

Merging #9733 into master will decrease coverage by 0.01%.
The diff coverage is 53.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9733      +/-   ##
==========================================
- Coverage   70.49%   70.47%   -0.02%     
==========================================
  Files         402      402              
  Lines       12564    12577      +13     
  Branches     3112     3115       +3     
==========================================
+ Hits         8857     8864       +7     
- Misses       3593     3599       +6     
  Partials      114      114              
Flag Coverage Δ
#cypress 53.58% <53.84%> (+<0.01%) ⬆️
#javascript 58.87% <30.76%> (-0.03%) ⬇️
Impacted Files Coverage Δ
...et-frontend/src/dashboard/components/Dashboard.jsx 82.89% <50.00%> (-6.17%) ⬇️
superset-frontend/src/logger/LogUtils.js 100.00% <100.00%> (ø)
superset-frontend/src/SqlLab/actions/sqlLab.js 66.81% <0.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 865a909...d5f87d8. Read the comment docs.

start_offset: Logger.getTimestamp(),
ts: new Date().getTime(),
};
} else {
Copy link
Member

Choose a reason for hiding this comment

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

could we explicitly check if visibilityState === 'visible' here? I see some documentation talking about the prerender state which we probably want to ignore

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

// from hidden to visible
const logStart = this.visibilityEventData.start_offset;
this.props.actions.logEvent(LOG_ACTIONS_HIDDEN_BROWSER_TAB, {
...this.visibilityEventData.start_offset,
Copy link
Member

Choose a reason for hiding this comment

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

start_offset is a number i think, so wouldn't this fail when trying to spread a number?

I assume this should be ...this.visibilityEventData

Copy link
Author

Choose a reason for hiding this comment

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

correct. fixed.

@@ -19,6 +19,7 @@
// Log event names ------------------------------------------------------------
export const LOG_ACTIONS_LOAD_CHART = 'load_chart';
export const LOG_ACTIONS_RENDER_CHART = 'render_chart';
export const LOG_ACTIONS_HIDDEN_BROWSER_TAB = 'hidden_browser_tab';
Copy link
Member

Choose a reason for hiding this comment

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

almost all these event names use a verb to start them, although this event isn't really an action and instead is logging the duration of a state.

Maybe this should be LOG_DURATION_BROWSER_TAB_HIDDEN = 'duration_browser_tab_hidden'? I'm not really sure what a good name is here, maybe @john-bodley has thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

event name is hidden_browser_tab, duration is just one attribute of the event.

Copy link
Member

Choose a reason for hiding this comment

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

I guess my point is, we're not logging an event when the browser tab is hidden, rather we're logging the point when the tab becomes visible again. And the most valuable part of this is the amount of time it spent in the hidden state

Copy link
Author

Choose a reason for hiding this comment

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

This is a timing_event, like load_chart and render_chart.
To me start_offset is also valuable, I can see when user start to switch browser tab.
Even there is only one valuable attribute, duration, this hidden_browser_tab event still need to send other attribute like event_type and trigger_event so that this event will be grouped with correct dashboard load event.
So we need to send event not just an attribute.

Copy link
Member

Choose a reason for hiding this comment

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

load_chart and render_chart start with verbs, unlike hidden_browser_tab. So I recommend we find a better name for this action. Perhaps hide_browser_tab? make_browser_tab_hidden?

Copy link
Author

Choose a reason for hiding this comment

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

all your recommended names seems not ideal... i chose hide_browser_tab.

@graceguo-supercat graceguo-supercat force-pushed the gg-OpenDashHiddenTab branch 2 times, most recently from 3deae07 to d5f87d8 Compare May 5, 2020 05:41
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

hide_browser_tab seems good to me. thanks for addressing comments!

};
} else if (document.visibilityState === 'visible') {
// from hidden to visible
const logStart = this.visibilityEventData.start_offset;
Copy link
Member

Choose a reason for hiding this comment

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

do we need this extra variable if it's only being used once?

Copy link
Author

Choose a reason for hiding this comment

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

i feel readability will be better with an extra variable, when destructuring object with long attribute name.

@graceguo-supercat graceguo-supercat merged commit 0b963bd into apache:master May 5, 2020
@graceguo-supercat graceguo-supercat deleted the gg-OpenDashHiddenTab branch June 11, 2020 23:18
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.37.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 0.37.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants