{"id":20614376,"url":"https://github.com/gitsquared/rinzler","last_synced_at":"2025-04-07T10:28:06.719Z","repository":{"id":42684145,"uuid":"312346649","full_name":"GitSquared/rinzler","owner":"GitSquared","description":"An autonomous parallel processing engine for the browser.","archived":false,"fork":false,"pushed_at":"2024-12-16T10:49:24.000Z","size":2189,"stargazers_count":64,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-04T18:09:27.384Z","etag":null,"topics":["acceleration","webworkers"],"latest_commit_sha":null,"homepage":"https://rinzler.js.org","language":"TypeScript","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/GitSquared.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"GitSquared","custom":["https://gaby.dev/donate"]}},"created_at":"2020-11-12T17:20:30.000Z","updated_at":"2025-03-02T10:00:30.000Z","dependencies_parsed_at":"2023-02-09T17:01:46.562Z","dependency_job_id":"5d227407-22c2-4089-b810-0dda584129e1","html_url":"https://github.com/GitSquared/rinzler","commit_stats":{"total_commits":102,"total_committers":2,"mean_commits":51.0,"dds":0.1470588235294118,"last_synced_commit":"82f040dba91d6c6b302dc24bab92167512ddd8f5"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSquared%2Frinzler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSquared%2Frinzler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSquared%2Frinzler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GitSquared%2Frinzler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GitSquared","download_url":"https://codeload.github.com/GitSquared/rinzler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247634844,"owners_count":20970613,"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":["acceleration","webworkers"],"created_at":"2024-11-16T11:12:35.510Z","updated_at":"2025-04-07T10:28:06.696Z","avatar_url":"https://github.com/GitSquared.png","language":"TypeScript","funding_links":["https://github.com/sponsors/GitSquared","https://gaby.dev/donate"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"60%\" alt=\"Rinzler project logo\" src=\"https://github.com/GitSquared/rinzler/raw/master/media/rinzler_logo.svg\"/\u003e\n  \u003cbr/\u003e\u003cbr/\u003e\n  \u003ca href=\"https://npmjs.com/package/rinzler-engine\"\u003e\u003cimg alt=\"npm version badge\" src=\"https://img.shields.io/npm/v/rinzler-engine\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://npmjs.com/package/rinzler-engine\"\u003e\u003cimg alt=\"types included badge\" src=\"https://badgen.net/npm/types/rinzler-engine\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/GitSquared/rinzler/blob/master/LICENSE\"\u003e\u003cimg alt=\"license badge\" src=\"https://img.shields.io/npm/l/rinzler-engine\"/\u003e\u003c/a\u003e\n  \u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\n\u003c/div\u003e\n\n[Rinzler](https://github.com/GitSquared/rinzler) is a ~~turboramjet~~ **parallel processing engine** for the browser.\n\nIt speeds up your web application by allowing recurring functions to execute in parallel taking full advantage of the host system's available processing power.\n\nCheck out the [full docs](https://gitsquared.github.io/rinzler/classes/rinzlerengine.html), try the [interactive demo](https://rinzler-demo.vercel.app) or read on for a high-level overview and a quick start guide.\n\n## Concept\nMost devices have a processor unit (CPU) with multiple *cores*, meaning that they are capable of working on multiple tasks at the same time.\nModern operating systems with multi-tasking functionality (e.g the ability to run \u0026 manage multiple programs/windows) have a special component called a *thread scheduler*.\n\nEach program you run can have multiple *threads*, and the scheduler's job is to distribute threads to the CPU's cores.\n\nA web page's JavaScript normally executes on a single thread, meaning it will never use more than one CPU core. In most cases this is fine, and also helps ensures other tabs in the user's browser, or other programs, can also keep running smoothly.\n\nHowever, some web applications might need to process a lot of data, or do a lot of expensive computing, and therefore can benefit from spreading work across all the available cores of the host machine.\n\nRinzler is a tool to do just that, in the simplest way possible - just define functions to run in parallel, and use native ES6 [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises) to run \u0026 manage parallelized jobs.\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"90%\" alt=\"Infographic explaining how Rinzler allows you to use more CPU cores\" src=\"https://github.com/GitSquared/rinzler/raw/master/media/infographic.png\"/\u003e\n\u003c/div\u003e\n\nInternally, it leverages [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API), which is a standard Web API for executing code in separate threads. It also includes a custom scheduler that handles spawning new Workers when necessary, sharing work between them, and shutting them down when they're not used.\n\n## Install\n```\nnpm i rinzler-engine\n```\n\nBoth ES \u0026 UMD modules are bundled, as well as TypeScript types, so you should be all set.\n\nRinzler targets browsers with [WebWorkers](https://caniuse.com/webworkers) and [Promises](https://caniuse.com/promises) support (check the [browserslistrc](https://github.com/GitSquared/rinzler/raw/master/.browserslistrc)). Most modern evergreen browsers, including Edge, should be compatible.\n\n## Quick start\nIn the following example, we will set up a Rinzler-accelerated app that decodes [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)s of text.\n\n### 0. Environment initialization (optional)\nIn most real-life use cases, the job processing you will offload to Rinzler will depend on some dynamic variable in the context of your app: in this example, the original encoding of the text we want to decode.\n\nThe processing functions you will pass to Rinzler ***cannot contain references to external variables***, because their source code will be extracted and printed in the Worker instances' source.\n\nTo work around this limitation, Rinzler allows you to setup an \"initialization\" function and pass it a payload. This function \u0026 payload will be run on each new Web Worker instance before it starts processing your jobs.\n\n```js\nconst initOptions = [{\n  encoding: 'utf-8' // We're just going to print this here, but in real life you would probably get this option from user input.\n}]\n\nfunction init(options) {\n  // This will run once in new Web Worker contexts. We can use the `self` global to store data for later.\n  self.params = {\n    encoding: options.encoding\n  }\n}\n```\n\n### 1. Job processing function\nWe need to setup a function that will actually do the job we need to parallelize, in this case, decoding text buffers.\n\n```js\nfunction processJob(message) {\n  // We expect to receive an object with an `encodedText` prop that is an ArrayBuffer.\n  const buffer = message.encodedText\n\n  // Get the encoding parameter we stored earlier, or default to ASCII.\n  const encoding = self.params?.encoding || 'ascii'\n\n  const text = new TextDecoder(encoding).decode(buffer)\n  return [text]\n}\n```\n\n### 2. Engine start\nNext we will import Rinzler and start the engine by passing the function(s) we defined above.\n\nThe following code is written for asynchronous contexts, but you can translate it to synchronous by using `.then()` with a callback instead of `await`.\n\n```js\nimport RinzlerEngine from 'rinzler-engine'\n\nconst engine = await new RinzlerEngine().configureAndStart(processJob, init, initOptions)\n```\n\n### 3. Running jobs\nNow we can actually run jobs! We'll use the `runJob()` method, which returns a `Promise` that will resolve when the job is completed.\n\nSince we need to pass an `ArrayBuffer`, we'll use the second argument as a `Transferable[]` - much like in the native [`worker.postMessage()` API.](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage)\n\n```js\n// Encode some text to try our decoder with\nconst encodedText = new TextEncoder('utf-8').encode('hello Rinzler!')\n\n// Pass the encoded text to our decoding engine\nconst decodedResult = await engine.runJob({ encodedText }, [encodedText])\n\nconsole.log(decodedResult) // \"hello Rinzler!\"\n```\n\nYou can start as many jobs as you want, and take full advantage of ES6's asynchronous syntax (for example, [`Promise.all()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all)).\n\n**If you use TypeScript,** you can pass return types with the `runJob\u003cT\u003e(): Promise\u003cT\u003e` signature.\n\nUnder the hood, Rinzler will take care of launching Web Workers, balancing their load, and gracefully shutting them down when needed to reduce your app's memory footprint.\n\n### 4. Shutting down\nWeb Worker instances will be destroyed by the browser when the page exits, but you can schedule a graceful shutdown yourself using `engine.shutdown()`, which returns a `Promise` that will resolve once all currently active jobs have completed and all workers have been stopped.\n\n## Licensing\nRinzler is licensed under the [MIT License](https://github.com/GitSquared/rinzler/blob/master/LICENSE). You may integrate it in commercial applications.\n\n---\n\n###### © 2020-2022 Gabriel Saillard \u003cgabriel@saillard.dev\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitsquared%2Frinzler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitsquared%2Frinzler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitsquared%2Frinzler/lists"}