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

Measure callback timeout relative to current time #15479

Merged
merged 1 commit into from
Apr 23, 2019

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Apr 23, 2019

Fixes a bug where the timeout passed to scheduleCallback represented an absolute timestamp, instead of the amount of time until that timestamp is reached. The solution is to subtract the current time from the expiration.

The bug wasn't caught by other tests because we use virtual times that default to 0, and most tests don't advance time.

I also moved the initialTimeMs offset to the SchedulerWithReactIntegration module so that we don't have to remember to subtract the offset every time. (We should consider upstreaming this to the Scheduler package.)

Fixes a bug where the timeout passed to `scheduleCallback` represented
an absolute timestamp, instead of the amount of time until that
timestamp is reached. The solution is to subtract the current time
from the expiration.

The bug wasn't caught by other tests because we use virtual times that
default to 0, and most tests don't advance time.

I also moved the `initialTimeMs` offset to the
`SchedulerWithReactIntegration` module so that we don't have to remember
to subtract the offset every time. (We should consider upstreaming this
to the Scheduler package.)
@sizebot
Copy link

sizebot commented Apr 23, 2019

ReactDOM: size: 🔺+0.1%, gzip: 🔺+0.1%

Details of bundled changes.

Comparing: 9ebe176...36dc9da

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.development.js +0.1% +0.1% 810.69 KB 811.43 KB 185.02 KB 185.29 KB UMD_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 103.58 KB 103.63 KB 33.65 KB 33.68 KB UMD_PROD
react-dom.profiling.min.js 0.0% +0.1% 106.73 KB 106.79 KB 34.6 KB 34.62 KB UMD_PROFILING
react-dom.development.js +0.1% +0.2% 805.17 KB 805.91 KB 183.49 KB 183.77 KB NODE_DEV
react-dom.production.min.js 🔺+0.1% 🔺+0.1% 103.57 KB 103.63 KB 33.1 KB 33.13 KB NODE_PROD
react-dom.profiling.min.js +0.1% +0.1% 106.9 KB 106.96 KB 33.95 KB 33.99 KB NODE_PROFILING
ReactDOM-dev.js +0.1% +0.2% 829.52 KB 830.25 KB 184.87 KB 185.16 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+0.1% 🔺+0.1% 337.35 KB 337.53 KB 62.68 KB 62.72 KB FB_WWW_PROD
ReactDOM-profiling.js +0.1% +0.1% 342.74 KB 342.91 KB 63.61 KB 63.65 KB FB_WWW_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.1% 811.02 KB 811.75 KB 185.16 KB 185.43 KB UMD_DEV
react-dom-unstable-fire.production.min.js 🔺+0.1% 🔺+0.1% 103.6 KB 103.65 KB 33.66 KB 33.69 KB UMD_PROD
react-dom-unstable-fire.profiling.min.js 0.0% +0.1% 106.75 KB 106.8 KB 34.61 KB 34.63 KB UMD_PROFILING
react-dom-unstable-fire.development.js +0.1% +0.2% 805.5 KB 806.23 KB 183.62 KB 183.91 KB NODE_DEV
react-dom-unstable-fire.production.min.js 🔺+0.1% 🔺+0.1% 103.59 KB 103.65 KB 33.11 KB 33.14 KB NODE_PROD
react-dom-unstable-fire.profiling.min.js +0.1% +0.1% 106.91 KB 106.97 KB 33.96 KB 33.99 KB NODE_PROFILING
ReactFire-dev.js +0.1% +0.2% 828.71 KB 829.44 KB 184.89 KB 185.18 KB FB_WWW_DEV
ReactFire-prod.js 🔺+0.1% 🔺+0.1% 325.33 KB 325.5 KB 60.23 KB 60.28 KB FB_WWW_PROD
ReactFire-profiling.js +0.1% +0.1% 330.68 KB 330.85 KB 61.19 KB 61.23 KB FB_WWW_PROFILING
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 10.52 KB 10.52 KB 3.89 KB 3.9 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% -0.0% 60.76 KB 60.76 KB 15.85 KB 15.84 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% -0.0% 10.69 KB 10.69 KB 3.67 KB 3.66 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 19.18 KB 19.18 KB 7.21 KB 7.21 KB UMD_PROD
react-dom-server.browser.development.js 0.0% 0.0% 132.86 KB 132.86 KB 34.99 KB 34.99 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.1 KB 19.1 KB 7.2 KB 7.2 KB NODE_PROD
ReactDOMServer-dev.js 0.0% 0.0% 134.95 KB 134.95 KB 34.61 KB 34.61 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 47.14 KB 47.14 KB 10.8 KB 10.8 KB FB_WWW_PROD
react-dom-server.node.development.js 0.0% 0.0% 134.8 KB 134.8 KB 35.53 KB 35.54 KB NODE_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 19.96 KB 19.96 KB 7.51 KB 7.51 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.66 KB 3.66 KB 1.45 KB 1.45 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.1% 1.21 KB 1.21 KB 706 B 705 B UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% -0.2% 1.05 KB 1.05 KB 636 B 635 B NODE_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.74 KB 3.74 KB 1.43 KB 1.43 KB NODE_DEV

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.1% +0.2% 556.46 KB 557.2 KB 121.46 KB 121.74 KB UMD_DEV
react-art.production.min.js 🔺+0.1% 0.0% 95.49 KB 95.54 KB 29.31 KB 29.33 KB UMD_PROD
react-art.development.js +0.2% +0.3% 487.49 KB 488.22 KB 104.07 KB 104.35 KB NODE_DEV
react-art.production.min.js 🔺+0.1% 🔺+0.2% 60.46 KB 60.52 KB 18.61 KB 18.64 KB NODE_PROD
ReactART-dev.js +0.1% +0.3% 496.65 KB 497.38 KB 103.13 KB 103.41 KB FB_WWW_DEV
ReactART-prod.js 🔺+0.1% 🔺+0.1% 194.93 KB 195.1 KB 33.15 KB 33.19 KB FB_WWW_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +0.1% +0.2% 628.2 KB 628.93 KB 133.33 KB 133.6 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 243.71 KB 243.87 KB 42.35 KB 42.39 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 251.89 KB 252.05 KB 43.92 KB 43.96 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +0.1% +0.2% 628.12 KB 628.85 KB 133.29 KB 133.57 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+0.1% 🔺+0.1% 243.72 KB 243.88 KB 42.35 KB 42.39 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +0.1% +0.1% 251.91 KB 252.07 KB 43.92 KB 43.96 KB RN_OSS_PROFILING
ReactFabric-dev.js +0.1% +0.2% 616.89 KB 617.62 KB 130.62 KB 130.89 KB RN_FB_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 237.48 KB 237.64 KB 41.09 KB 41.13 KB RN_FB_PROD
ReactFabric-profiling.js +0.1% +0.1% 245.13 KB 245.29 KB 42.7 KB 42.74 KB RN_FB_PROFILING
ReactFabric-dev.js +0.1% +0.2% 616.79 KB 617.53 KB 130.58 KB 130.86 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+0.1% 🔺+0.1% 237.49 KB 237.65 KB 41.09 KB 41.12 KB RN_OSS_PROD
ReactFabric-profiling.js +0.1% +0.1% 245.14 KB 245.3 KB 42.7 KB 42.74 KB RN_OSS_PROFILING

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +0.1% +0.3% 500.9 KB 501.63 KB 106.78 KB 107.06 KB UMD_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.2% 61.68 KB 61.74 KB 18.93 KB 18.96 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.3% 496.44 KB 497.17 KB 105.68 KB 105.95 KB NODE_DEV
react-test-renderer.production.min.js 🔺+0.1% 🔺+0.1% 61.36 KB 61.42 KB 18.8 KB 18.81 KB NODE_PROD
ReactTestRenderer-dev.js +0.1% +0.3% 507.22 KB 507.95 KB 105.37 KB 105.64 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 41.88 KB 41.88 KB 10.7 KB 10.71 KB UMD_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 36.11 KB 36.11 KB 9.36 KB 9.36 KB NODE_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.2% +0.3% 485.02 KB 485.75 KB 102.51 KB 102.79 KB NODE_DEV
react-reconciler.production.min.js 🔺+0.1% 🔺+0.1% 61.39 KB 61.45 KB 18.35 KB 18.38 KB NODE_PROD
react-reconciler-persistent.development.js +0.2% +0.3% 482.93 KB 483.66 KB 101.62 KB 101.9 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+0.1% 🔺+0.1% 61.4 KB 61.46 KB 18.36 KB 18.38 KB NODE_PROD

Generated by 🚫 dangerJS

@acdlite acdlite merged commit 71c8759 into facebook:master Apr 23, 2019
export const shouldYield = disableYielding
? () => false // Never yield when `disableYielding` is on
: Scheduler_shouldYield;

let immediateQueue: Array<SchedulerCallback> | null = null;
let immediateQueueCallbackNode: mixed | null = null;
let isFlushingImmediate: boolean = false;
let initialTimeMs: number = Scheduler_now();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be const?

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