[MOVED] ThreadRecycler: Recycle and reuse threads! | v0.2.2

ThreadRecycler

A thread management module strictly written in Luau.

Moved

:warning: (Currently unlisted after a recent benchmark using Benchmaker. I may request this to be public again after I fix the issues?)


GitHub Repo | Documentation & Tutorial | Releases | Last updated: 2/4/25

Performance

ThreadRecycler optimizes thread usage by recycling and reusing it, which reduces resource consumption. Fewer resources are wasted on unnecessary threads, which leads to faster execution.

Limitations

  • Must replace task.wait() with ThreadRecycler.wait() to prevent issues in the task library (more context in the documentation. However, if you only use ThreadRecycler.wrap(), this step might not be necessary.
  • Using ThreadRecycler.defer() and ThreadRecycler.delay() isn’t broken per se, but due to task library issues, an alternative is strongly recommended.
    • (Possible warning if used) “task.defer should not be called on a thread that is already ‘deferred’ in the task library”
  • As this is my first open-source and public module, it may require significant improvements.

Benchmarks

Figure

(Note: I don’t really know how to accurately benchmark this module, haven’t done a benchmark before. The problem with the benchmarking I did is that more threads are created if the heartbeat rate is lower as I have it under a while loop.)

Input (x): Workload | Output (y): Heartbeat time (s)
Workload in this case is property changes, networking, and calculations.

Full benchmark results are in the documentation.

Installation (via GitHub Releases)

Head over to releases and download the .rbxm file from the latest version. Then, insert the .rbxm file into Roblox Studio.

Require the module:

local ThreadRecycler = require(game.GetService(game, "ReplicatedStorage").ThreadRecycler)

I strongly recommend that you use the documentation for more in-depth details.

License

ThreadRecycler is fully open-source and free to use with a MIT license.

Contributions

All contributions are welcome! :)

2 Likes

This doesn’t seem significant enough for people to change all their scripts to work with this. :sweat:

1 Like

a spawner with thread pooling would probably achieve the goal better than this

Currently working on v0.3 which is a lot faster than v0.2.x.
Got a plugin from a friend which creates histograms:


(This benchmark was run on v0.3, not v0.2.x)

It has always been a thread pool, although you can consider it to be a “global” thread pool w/o anything such as Module.new().

why would it need x.new, it should return a single function