{"id":21367923,"url":"https://github.com/luhsra/rt.js","last_synced_at":"2025-07-13T05:31:54.745Z","repository":{"id":57355774,"uuid":"206509656","full_name":"luhsra/RT.js","owner":"luhsra","description":"A real-time capable pseudo-preemptive scheduler for JavaScript","archived":false,"fork":false,"pushed_at":"2020-08-18T12:44:41.000Z","size":448,"stargazers_count":19,"open_issues_count":2,"forks_count":5,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-24T03:21:23.881Z","etag":null,"topics":["javascript","preemption","real-time","transpiling","typescript"],"latest_commit_sha":null,"homepage":"https://www.sra.uni-hannover.de/Research/rtjs/index.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luhsra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-05T08:08:16.000Z","updated_at":"2024-02-15T13:44:58.000Z","dependencies_parsed_at":"2022-09-05T22:12:41.009Z","dependency_job_id":null,"html_url":"https://github.com/luhsra/RT.js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luhsra%2FRT.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luhsra%2FRT.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luhsra%2FRT.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luhsra%2FRT.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luhsra","download_url":"https://codeload.github.com/luhsra/RT.js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225857656,"owners_count":17535260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","preemption","real-time","transpiling","typescript"],"created_at":"2024-11-22T07:21:27.971Z","updated_at":"2024-11-22T07:21:28.507Z","avatar_url":"https://github.com/luhsra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RT.js: Practical Real-Time Scheduling for Web Applications\n\nRT.js is a framework that provides preemptive and prioritized scheduling of JavaScript jobs.\nJavaScript interpreters execute all jobs (i.e., event handlers) strictly in order and in a run-to-completion semantic.\nWhile a job is being executed, there is no way to yield the execution engine before the calculation has finished.\nMeanwhile, not only the JS-interpreter thread is blocked, but, more importantly, the rendering of the web page is delayed until the interpreter handed back control to the rendering engine.\nIn fact, a JavaScript event handler may busy wait on something and starve all other jobs, the renderer of the browser tab, and the whole web page.\nWe can see the effect of long running computations in a benchmark where computation-intense JS code is competing with UI update code for the interpreter. The benchmark can also be found [here](https://www.sra.uni-hannover.de/Research/rtjs/demo.html).\n\n![](macro-benchmark.png)\n\nRT.js tackles this problem by inserting explicit preemption points into long-running JS functions via transpilation (i.e., source-to-source compiling) of the source code.\nWe provide an abstraction to submit such transpiled functions as RT.js jobs with a given scheduling priority or with a relative execution deadline.\nThe RT.js scheduler executes the given jobs according to their relative importance, periodically regains control over the interpreter by the inserted preemption points, and regularly returns to the browser, which then can decide what to do next (e.g., page rendering).\n\nThe transpiler achieves preemptability by converting every function marked with the `@rtjs` or `// @rtjs` decorator to a generator function, meaning that the run-time system allows returning from that function prematurely and re-entry into that function.\nThe run-time system keeps the state of the function and the local objects.\nPreemption points are added by inserting `yield`-statements on the following occasions:\n\n- before `while` and `for` loop bodies, i.e. on every iteration of the loop\n- before function calls\n- before `if` statements\n\nBoth [Mozilla][2] and [Google][1] suggest either not using the main-thread (i.e. creating web workers for complex computations, with their own drawbacks) or splitting up the computations on the main thread. RT.js does that automatically and allows you to prioritize your work load. Compute intensive tasks can be offloaded to be executed when the RT.js scheduler runs next, whereas small event handlers can still be run without using the services of RT.js.\n\n## Conference Publication at RTSS 2019\n\n\u003e [RT.js: Practical Real-Time Scheduling for Web Applications](https://www.sra.uni-hannover.de/Publications/publications.html#dietrich:19:rtss). Christian Dietrich, Stefan Naumann, Robin Thrift, Daniel Lohmann. Proceedings of the 40th IEEE Real-Time Systems Symposium 2019. IEEE Computer Society Press. 2019\n\n## Project Directory Structure\n\n- `src` contains the main source files for the runtime and transpiler (source to source compiler).\n- `src/transpiler` contains the transpiler code.\n- `benchmarks` contains a number of benchmarks of different kinds.\n  - `benchmarks/qualitative` is the macro benchmark from the RTSS publication. It contains a website running in a browser showcasing RT.js against the default run-to-completion policy of the JavaScript run-time engine. (you'll need `plotly-base` to use that benchmark).\n  - `benchmarks/minimal` contains a small example project that uses RT.js to introduce pseudo-preemptivity.\n\nAfter building the transpiler (see below), the `build`-folder exists, containing the transpiled RT.js library and the transpiler, ready for use.\n\n## Installation and Setup\n\n- `npm install`: Install all required dependencies (especially TypeScript).\n- `make build`: Build the RT.js transpiler. Please note: The benchmarks will build the transpiler as an dependency.\n- `make docs`: Generate a browsable version of the API docs in ./docs\n\n## Basic Usage\n\nTo allow for scheduling all tasks must inherit from the `Task`-class and override the `run`-method:\n\n```javascript\nimport { Task } from \"Task\"\n\nclass MyTask extends Task {\n    // @rtjs\n    *run() {\n        var i = 0;\n        while (i \u003c 1000000) {\n           i++;\n        }\n        // implement your task here\n    }\n}\n```\n\nNote that every method that should be transformed needs to be prefixed by the `@rtjs`-decorator. Functions can also be made schedulable and preemtible by simply prefixing them with the same `@rtjs`-decorator (or inside a comment for pure JavaScript `// @rtjs`).\n\nTo transpile the code use the `rtjs-transpiler.js` tool in `build/transpiler`, e.g.:\n\n```\nbuild/transpiler/rtjs-transpiler \"MyTask.js\"\ncat build/MyTask.js\n```\n\n\u003e NOTE: Currently the output directory is always `build`\n\n[1]: https://developers.google.com/web/fundamentals/performance/rendering/ \"Rendering Performance: Google\"\n[2]: https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Performance_best_practices_for_Firefox_fe_engineers \"Performance best practices for Firefox front-end engineers\"\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluhsra%2Frt.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluhsra%2Frt.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluhsra%2Frt.js/lists"}