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

add Profiler.increment and Profiler.frame #2196

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

mzgoddard
Copy link
Contributor

@mzgoddard mzgoddard commented Jun 5, 2019

Resolves

Scratch performance when the profiler is recording.

Proposed Changes

Let profiled code track frames and arguments called by incrementing a counter for a frame id or frame id and argument. This replaces the same counting by recording the call as part of a history of calls and returns. Updating the array for all calls counted takes enough time to bias the profiled run towards less overall executions.

Reason for Changes

Scratch performance has improved to the point again that we need to change how the Profiler records performance to spend more time executing blocks than spending time recording that a block executed.

Benchmark Data

These numbers indicate a large improvement. Take note this improvement is only affecting when profiling is recording. This is a scratch developer facing improvement so we can get a better measure a change will make while developing the change and reviewing the change.

device project id warm up (s) before (bps) after (bps) difference change
chrome mbp 15" 2017 130041250 0 803343 1338256 534913 66.59%
chrome mbp 15" 2017 130041250 4 1038659 1715644 676985 65.18%
chrome mbp 15" 2017 14844969 0 1259861 1922094 662233 52.56%
chrome mbp 15" 2017 14844969 1 1393017 2238741 845724 60.71%
chrome mbp 15" 2017 173918262 0 1120676 1853687 733011 65.41%
chrome mbp 15" 2017 173918262 5 1149243 1602950 453707 39.48%
chrome mbp 15" 2017 155128646 0 1011027 2084500 1073473 106.18%
chrome mbp 15" 2017 155128646 5 856636 855513 -1123 -0.13%
chrome mbp 15" 2017 89811578 0 1550713 2469557 918844 59.25%
chrome mbp 15" 2017 89811578 5 1711245 2640594 929349 54.31%
chrome mbp 15" 2017 139193539 0 1398716 2378486 979770 70.05%
chrome mbp 15" 2017 139193539 5 1462682 2508699 1046017 71.51%
chrome mbp 15" 2017 187694931 0 863060 2118414 1255354 145.45%
chrome mbp 15" 2017 187694931 5 980702 2220644 1239942 126.43%
chrome mbp 15" 2017 219313833 0 164755 176664 11909 7.23%
chrome mbp 15" 2017 219313833 5 165293 182444 17151 10.38%
chrome mbp 15" 2017 236115215 0 5268 5553 285 5.41%
chrome mbp 15" 2017 236115215 5 5289 5526 237 4.48%
chrome mbp 15" 2017 238750909 0 90887 91218 331 0.36%
chrome mbp 15" 2017 238750909 5 96803 94128 -2675 -2.76%

src/engine/execute.js Outdated Show resolved Hide resolved
src/engine/execute.js Outdated Show resolved Hide resolved
if (blockCached._profiler !== runtime.profiler) {
prepareBlockProfiling(runtime.profiler, blockCached);
}
const end = Math.min(i + 1, length);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment about what this calculation is? It's difficult to keep track of units and what i and length correspond to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

// Determine the index that is after the last executed block. `i` is
// currently the block that was just executed. `i + 1` will be the block
// after that. `length` with the min call makes sure we don't try to
// reference an operation outside of the set of operations.

src/engine/profiler.js Outdated Show resolved Hide resolved
Copy link
Contributor

@kchadha kchadha left a comment

Choose a reason for hiding this comment

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

A few questions and minor changes requested inline.

@kchadha kchadha assigned mzgoddard and unassigned kchadha Jun 24, 2019
@rschamp rschamp removed their assignment Jul 8, 2019
@mzgoddard
Copy link
Contributor Author

  • Update code to fulfill requested changes.

Let profiled code track frames and arguments called by incrementing a
counter for a frame id or frame id and argument. This replaces the same
counting by recording the call as part of a history of calls and
returns. Updating the array for all calls counted takes enough time to
bias the profiled run towards less overall executions.
@kchadha
Copy link
Contributor

kchadha commented Sep 16, 2019

LGTM but I think I want to get a second pair of eyes on this (either @cwillisf or @rschamp maybe?). I can confirm that I see a large improvement in the benchmark numbers being reported!

@kchadha kchadha requested review from cwillisf and rschamp September 17, 2019 00:01
@kchadha kchadha modified the milestones: July 2019, September 2019 Sep 18, 2019
@kchadha kchadha merged commit 8bba60a into scratchfoundation:develop Oct 1, 2019
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