Comments (7)
cc @robik :)
from react-native.
@rubennorte I've put up a draft PR: #44759
Currently, this is for preview only, and pretty much untested. Feel free to point out what should be changed and whenever we want to extract some of the code into separate class as initially planned.
I am looking for a way to register the methods from NativeMicrotasks
module into globals so they are visible in bridgeless mode. I am pretty unsure whenever it is a good approach that the logic was done in turbo module or it should be moved.
Also I am bit unsure if all cases were covered (e.g. bridgeless, bridge, flags etc) so there may be some missing parts in this regard
from react-native.
Missing Reproducible Example | |
---|---|
âšī¸ | We could not detect a reproducible example in your issue report. Please provide either:
|
from react-native.
At a high level, this is how I'd implement this:
- Create an abstraction to handle idle callbacks, which would keep a queue of idle callbacks and would handle their promotion from idle callbacks to regular tasks after their timeout (we can just schedule a timer with the specified timeout, if any, which would execute the task and cancel the idle callback).
- Modify
RuntimeScheduler_Modern
to receive an idle callback queue (probably as an interface that the previous abstraction would implement, to avoid dependency cycles in C++). When there are no tasks left in the task queue, those tasks would be consumed). For the timeRemaining function, we could compute the deadline at the beginning of the idle period using now + 50ms. We don't need frame alignment as in the spec (and the spec doesn't require it). In that method we should also checkshouldYield
in the scheduler and return 0 if that's the case. - Create a C++ TurboModule to expose
requestIdleCallback
, similar to what we did withqueueMicrotask
(module) (global). This should register the microtask in the new abstraction created in step.
The idle callbacks instance should probably be owned by ReactInstance
because that's where we have access to the timer manager (to promote idle callbacks) and to the runtime scheduler. The native module can access it from RuntimeSchedulerBinding
.
from react-native.
I've been thinking about this a bit more and there an alternative implementation we could use that perhaps would be simpler (although its alignment with the spec would be harder to "visualize").
Instead of keeping a separate queue for idle callbacks and specific logic in the scheduler, we can keep the scheduler unmodified and schedule all idle callbacks as idle priority tasks. The only extra thing we'd need is the native module I mentioned in my previous comment and the abstraction for promoting idle callbacks to regular tasks after the timeout. At a high level:
- Create an abstraction to handle the execution idle callbacks and their promotion to regular tasks after their timeout (e.g.
IdleCallbackScheduler
) (we can just schedule a timer with the specified timeout, if any, which would execute the task and cancel the idle callback). - Create a C++ TurboModule to expose requestIdleCallback, similar to what we did with queueMicrotask (module) (global). This should register the microtask in the new abstraction created in step.
This abstraction (IdleCallbackScheduler
or similar) would schedule an idle priority task in the scheduler which, when executed, would compute an initial deadline for the callback (e.g.: current time + 50ms) and would call the idle callback with an object that would return the right timeRemaining
based on that time (and 0
if getShouldYield
returns true
). In the future, we can make this more spec compliant looking also at what's the expiration time for the next timeout callback to execute (we don't need to do this in this version).
from react-native.
@rubennorte I've noticed that the RuntimeScheduler
has a priority queue based on task expirationTime
already, it initially had priority, so there's some groundwork for it being handled in the scheduler itself. If we want to separate this and introduce an API boundary should we revert it to be priority-based?
It might be a bit confusing and error-prone in the current state, WDYT?
from react-native.
@rubennorte I've noticed that the
RuntimeScheduler
has a priority queue based on taskexpirationTime
already, it initially had priority, so there's some groundwork for it being handled in the scheduler itself. If we want to separate this and introduce an API boundary should we revert it to be priority-based?
The expiration time in the RuntimeScheduler is just an implementation detail. It's just used to make sure that lower priority tasks execute eventually (except for idle priority tasks that have an infinite timeout), instead of being continuously deprioritized from new incoming tasks with a higher priority.
It might be a bit confusing and error-prone in the current state, WDYT?
The reason I was suggesting this approach was to avoid introducing new changes to the scheduler that we might regret later. Someone proposed allowing us to specify the scheduler timeout directly in the RuntimeScheduler API, but I think that wouldn't be a good idea.
Alternatively, we could do this:
- Add new methods in the RuntimeScheduler to schedule idle tasks with a timeout. Those methods would schedule tasks with an expiration time equals to something like
max(customTimeout, timeoutForSchedulerPriority(NormalPriority))
. This minimum time would be necessary to avoid that idle callbacks take higher priority than UserBlocking tasks when called with timeout equals 0. - Call these methods directly from the native module that I mentioned before, which would also wrap the callback to implement the
timeRemaining
method.
from react-native.
Related Issues (20)
- React Native 0.74.0 - Getting issue on production build -Crashed: Thread: SIGSEGV 0x0000006df6aebf90 HOT 6
- FlatList Items Not Occupying Full Screen Height with Paging Enabled HOT 3
- [Android] ScrollView does not properly handle `testID` property
- Application Scene Delegates support in RN >= 0.74 HOT 5
- How to initialize a react-native app of version 0.75.2 in year 2024? HOT 11
- Codegen resolves wrong dependency in multi-app monorepo; when apps specify different versions of same dep (ios) HOT 7
- Why support only Ukraine but not Palestine?Either support both or support neither. Why bring selective support into technology? HOT 4
- Tried to show an alert while not attached to an Activity HOT 5
- Unable to use Hermes engine in fresh CLI project HOT 10
- [email protected] / Android / New Arch - Bug HOT 5
- ForceRTL(false) is not working as intended HOT 6
- Bug: TextInput with multiline and lineHeight has height issue when controlled HOT 3
- [[email protected]] `yoga/style/Style.h` file not found HOT 10
- Creating a module with New Architecture and including a .swift file introduces compiler errors HOT 11
- [v0.75.2] macOS (Catalyst) builds fail with `hermes.framework: bundle format is ambiguous (could be app or framework)` HOT 27
- `Text` Components Positioned with bottom: 0 Gets Hidden Behind Navigation Bar on Android Devices HOT 29
- TypeError: Cannot read property 'create' of undefined, HOT 5
- Direct JSC debugging cannot be used in Mac simulator from 0.74.1 HOT 4
- Empty dSYM issue HOT 8
- * Where: Settings file 'C:\Users\Debasis\Desktop\vipani-app\android\settings.gradle' line: 13 * What went wrong: Error resolving plugin [id: 'com.facebook.react.settings'] HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native.