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(ext/web): optimize transferArrayBuffer #16294

Merged
merged 8 commits into from
Oct 26, 2022

Conversation

littledivy
Copy link
Member

Avoid copying enqueued data + misc optimizations to skip webidl converter.

10k rps increase in the SSR benchmark:

divy@mini ~/g/deno (optimize_readablestream)> wrk -d 5s --latency http://127.0.0.1:4500
Running 5s test @ http://127.0.0.1:4500
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   305.14us  339.21us   5.96ms   97.17%
    Req/Sec    18.14k     1.87k   19.70k    94.12%
  Latency Distribution
     50%  254.00us
     75%  276.00us
     90%  310.00us
     99%    1.75ms
  184115 requests in 5.10s, 31.78MB read
Requests/sec:  36100.65
Transfer/sec:      6.23MB

divy@mini ~/g/deno (optimize_readablestream)> wrk -d 5s --latency http://127.0.0.1:4500
Running 5s test @ http://127.0.0.1:4500
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   208.89us   66.70us   2.29ms   94.78%
    Req/Sec    23.47k     1.69k   24.50k    92.16%
  Latency Distribution
     50%  201.00us
     75%  218.00us
     90%  240.00us
     99%  415.00us
  238119 requests in 5.10s, 41.10MB read
Requests/sec:  46694.50
Transfer/sec:      8.06MB

ext/web/06_streams.js Outdated Show resolved Hide resolved
O[isFakeDetached] = true;
return transferredIshVersion;
const v = ops.op_transfer_arraybuffer(O);
v[isFakeDetached] = true;
Copy link
Contributor

@marcosc90 marcosc90 Oct 15, 2022

Choose a reason for hiding this comment

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

Suggested change
v[isFakeDetached] = true;
v[isFakeDetached] = true;
return v;

CI is failing because v is not being returned.

Copy link
Contributor

@marcosc90 marcosc90 Oct 15, 2022

Choose a reason for hiding this comment

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

deno/ext/web/06_streams.js

Lines 196 to 198 in 2300a70

function isDetachedBuffer(O) {
return ReflectHas(O, isFakeDetached);
}

And maybe we can now change that method to:

function isDetachedBuffer(O) { 
  return O.byteLength === 0;
} 

Although it may trigger some false positives.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm keeping isFakeDetached to not touch a lot of code.

Copy link
Member

Choose a reason for hiding this comment

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

I'm keeping isFakeDetached to not touch a lot of code.

Could you fix this properly rather than half fixing it just enough so that WPT passes? 😉

Copy link
Member Author

Choose a reason for hiding this comment

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

@lucacasonato #16307 @marcosc90 opened a PR to do that as a follow up to this one.

underlyingSourceDict = webidl.converters.UnderlyingSource(
underlyingSource,
{ prefix, context: "underlyingSource" },
);
}
Copy link
Member

Choose a reason for hiding this comment

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

      if (underlyingSource === undefined) {
        underlyingSource = null;
      }

This check is now not present at all anymore. underlyingSource is passed to a child function further down.

@bartlomieju
Copy link
Member

#16307 has landed, please rebase this PR @littledivy

@littledivy littledivy merged commit 6cd9343 into denoland:main Oct 26, 2022
bartlomieju pushed a commit that referenced this pull request Oct 26, 2022
Removed "fake detached" logic since it's no longer needed after
[#16294](#16294) landed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants