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/napi): port NAPI to v8 tasks #21406

Merged
merged 5 commits into from
Dec 11, 2023
Merged

Conversation

mmastrac
Copy link
Contributor

@mmastrac mmastrac commented Nov 30, 2023

Part 2 of removing middleware.

This is somewhat awkward because V8CrossThreadTaskSpawner requires tasks to be Send, but NAPI makes heavy use of !Send pointers. In addition, Rust causes a closure to be !Send if you pull a !Send value out of a struct.

@mmastrac mmastrac changed the title chore: port NAPI to v8 tasks [WIP] perf(ext/napi): port NAPI to v8 tasks [WIP] Nov 30, 2023
@mmastrac
Copy link
Contributor Author

mmastrac commented Dec 1, 2023

@littledivy This one seems to be working, but I need a bit of help coming up with a test plan to make sure that it works as expected. Do you know of a good npm package to test it with?

@littledivy
Copy link
Member

@mmastrac https://www.npmjs.com/package/@parcel/watcher is a good one for testing thread safe functions.

Comment on lines +89 to +92
#[repr(transparent)]
struct SendPtr<T>(*const T);
unsafe impl<T> Send for SendPtr<T> {}
unsafe impl<T> Sync for SendPtr<T> {}
Copy link
Member

Choose a reason for hiding this comment

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

SendPtr from cli/napi/async.rs can be reused here?

cli/napi/threadsafe_functions.rs Outdated Show resolved Hide resolved
context: SendPtr<c_void>,
data: SendPtr<c_void>,
) {
// SAFETY: We're calling the provided callback with valid args
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

);

fn event_loop_middleware(
Copy link
Member

Choose a reason for hiding this comment

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

Nice

@mmastrac mmastrac changed the title perf(ext/napi): port NAPI to v8 tasks [WIP] perf(ext/napi): port NAPI to v8 tasks Dec 11, 2023
Copy link
Member

@littledivy littledivy left a comment

Choose a reason for hiding this comment

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

LGTM

@mmastrac mmastrac merged commit d13e45f into denoland:main Dec 11, 2023
14 checks passed
littledivy added a commit that referenced this pull request Dec 14, 2023
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.

2 participants