-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
src: add a fast call for URL.revokeObjectURL #47794
Draft
debadree25
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
debadree25:ft/fast-call-revoke
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+95
−28
Draft
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
src: add a fast call for URL.revokeObjectURL
Refs: #47728
- Loading branch information
commit 869ff2a63c743e42604056d34d7fb9820dedba27
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
const assert = require('node:assert'); | ||
const { Blob } = require('buffer'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e6], | ||
}); | ||
|
||
function main({ n }) { | ||
const blob = new Blob(['hello']); | ||
let id = ''; | ||
bench.start(); | ||
for (let i = 0; i < n; i += 1) { | ||
id = URL.createObjectURL(blob); | ||
URL.revokeObjectURL(id); | ||
} | ||
assert.ok(id); | ||
bench.end(n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joyeecheung You used
Local<v8::Object>
for the receiver, whereas, inCanParse
@KhafraDev usedLocal<v8::Value>
for the receiver. Which one is the correct usage for the Fast API, or is both of them correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strings returned by
createObjectURL()
are cons strings. They won't hit the fast API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this documented? How can we update the benchmark to flatten the string?
(For people who didn't know what
cons strings
mean: cons strings are pairs of strings, result of concatenation.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
hello-1-2-3
as an input triggers fast api, but evencrypto.randomUUID()
as a parameter does not trigger fast API...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FastOneByteString
means the string type is a sequential one byte string. The string types are internal to V8 and subject to changes. I don't think it's meaningful to flatten the string in the benchmark if users in the wild are going to pass urls returned bycreateObjectURL()
to it...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JS-land version buffers the UUID so to match the performance the C++ version needs to buffer the UUID as well. Also
snprintf()
can be slow if it's heavily used.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think doing all this would probably make the C++ side way more complicated than the original TODO intended, is there no faster way of string allocation on C++ side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also just merge the concatenation in
createObjectURL()
from JS land intoBlob::StoreDataObject
and concatenate the strings from C++ instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string should be created with
NewFromOneByte()
, notNewFromUtf8()
as in 268fc13 because it's guaranteed to be one-byte and does not need transcoding.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay so i tried this
fast paths are being hit and perf is maybe little bit better than 268fc13 but on the benchmark in the commit, its still slower than the normal js version unfortunately 😓