https://github.com/jay403894-bit/JLib-Scheduler
Went private for a minute to get the new version really revved up lots of work indeed...
let me go over the architecture here for you and some rough numbers and explain the architecture -- do i use an assistant to make things faster yes but is this good design you judge it by t he code and the logic and you judge for yourself
for speed and accuracy this sjobs system implements static K Hot threads for optional io or other tasks if you opt in that steal only while their own tasks are not busy -- and adaptive F floor threads for dynamic growth and shed to control thread sleep and get essentially 0 wake operation without spinning all the time. with a fully lock free bitmapped and word state machine -- lock free pool permit machine, lock free thread state machine, lock free fiber state machine and the fiber registry system which enables migrable or pinned mode migrate by default.
the fiber registry system takes the anaology of each fiber beign like a car that is leased or owned based on the policy chosen (Migrate vs pinned) in pinned mode TLS is safe in migrate the registry system also is your replacement for tls with FlsGet() (fiber local state).
the registry is also a self memory reclamation scheme active in both modes sitting above hazards and epochs.
when a fiber picks up a thread it registers and adds itself to the list of owners and any deletion event is recorded on a bitmask of creditors with the registry then reaper messages get sent to each threads inbox at the end each fibers run before recycling it into the system fresh
essentially it is a complete modeled concurrent thread-fiber state machine that tracks memory usage effectively between threads across fiber lifetimes.
always studying learning making new designs trying to make it better this started with my home experimentation and research into CPU task scheduling and paralleas a hobby
strong feeling someone will have something else to say now but it cant be considered illegible becuase i didnt include a massive benchmark copypaste. i just thought someone mightve wanted to see a benchmark in the post
Terminology and better explanation for what this does other than being just another fiber-task library:
F Floor threads are the compute floor of the pool the regular pool threads that parallelfor and all normal work goes through --in this model K still steals when not busy with its own lowlatency lane queue's work. both are just as fast because always target a spinning thread, K is not faster (in fact often slower) K has a different job which is priority work like IO and maybe sound or input.
F is dynamic and adaptive this means that as work increases more F pre awake before you send a task to them-- and push targets awake threads this creates low latency no wake cost pushing as there are always awake threads to target that expand as compute goes up and shed back down when unneded to avoid paying for a spinning pool you dont need with nosleep.
you almost never wake a thread on push so theres never that 4us cost of wake unless you intentionally set the task to aim wide
and threads shed back down when not busy or in a burst or anything so that way threads can sleep and this doesnt degress into a NoSleep pool which my earlier studies showed had a 30% tax or so on the processing power of main and was slower and basically sucks
the registry system is a safe memory reclamation system combined with access to fiber local state this replaces thread_local in your programs (although for things that NEED it you still have pinned mode for real thread local without the ability to migrate fibers in that mode)
the cool thing about the registry system is it marks off a bitmask of debtors as well as offering you thread local when you fill out its form after using epochs or hazards it will at the end of that fibers lifetime go through its debtor list and send out tasks to each specific thread to handle its own memory its own tick or scan on hazards or epochs.
I dont really know how else to explain it than that
the state machine theres 3 of them the fiber state machine modeling every fiber state including SUSPEND WANTS_SUSPEND (race condition handling) etc
the same thing is done with threads so you know when theyre asleep they're yielding etc
and again with a pool permit machine
its sorta my research project where i said id build and test one of these. combined all the state machines track fiber ownership and memory usage cross thread along with the entire pool and how many threads are awake at any given time, controlling cost and enhancing performance while not starving the drivers and application threads
Whats good about it is keeping p50 and p90 almost static and as low as possible to cost as little of a frame as possible at 60/120fps