Skip to content

Conversation

poneciak57
Copy link
Contributor

Improved performance of worklet runner.

  • Moved all running logic to the WorkletsRunner.
  • Moved worklet deserialization into jsi::Function to constructor
  • decreased multiple locks when running
  • removed locking the runtime when we own the runtime (for AudioRuntime)

⚠️ Breaking changes ⚠️

Introduced changes

  • significantly improved worklet based nodes performance

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added/Conducted relevant tests
  • Performed self-review of the code
  • Updated Web Audio API coverage
  • Added support for web


/// @note We want to avoid automatic destruction as
/// when runtime is destroyed, underlying pointer will be invalid
char unsafeWorklet[sizeof(jsi::Function)];
Copy link

Choose a reason for hiding this comment

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

You could store <worklets::SerializableWorklet> as it does the same memoization as well (see RetainingSerializable super class).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ill check this out

#if RN_AUDIO_API_ENABLE_WORKLETS
unsafeRuntimePtr = &strongRuntime->getJSIRuntime();
strongRuntime->executeSync(
[this, shareableWorklet](jsi::Runtime &rt) -> jsi::Value {
Copy link

@tjzel tjzel Oct 9, 2025

Choose a reason for hiding this comment

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

The use of this here might result in crashes during reloads and in brownfield apps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is calling lambda synchronously do you still think that it would cause a crash ?

Comment on lines +72 to +80
std::optional<jsi::Value> WorkletsRunner::executeOnRuntimeUnsafe(
const std::function<jsi::Value(jsi::Runtime &)> &&job) const
noexcept(noexcept(job)) {
#if RN_AUDIO_API_ENABLE_WORKLETS
return job(*unsafeRuntimePtr);
#else
return std::nullopt;
#endif
};
Copy link

@tjzel tjzel Oct 9, 2025

Choose a reason for hiding this comment

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

If WorkletsRunner is not tied to the lifetime of the runtime this will crash during reloads and in brownfields.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is

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.

3 participants