Using multithreading to speed up an algorithm that interacts with components

Hello! I am not sure whether multithreading would be impossible in my case, but it seems conceivable, so I thought I would ask.

My game is calling a function almost every frame that has to either read or set state information from several very long lists of different components. It currently loops through all of those component lists, one after another, and records or sets all of their states. I’ve optimized as much as possible, but I believe I have reached a performance ceiling.

Since the function runs all in one frame, and it doesn’t matter in what order the components are read from or set, would it be possible to use multithreading or the Jobs system to divide the function into several pieces that can run concurrently?

Any advice would be much appreciated. Thanks!

Only the main application thread is allowed to read from Component. Additional threads attempting that will throw exceptions and often silently too. Those invisible exceptions won’t show up in your debug console without manually catching & forwarding them with try{code}catch(ex){LogException(ex)} block yourself.
One solution to this is to move that data out of Monobehaviour into dedicated Array, List or hashmap ( Dictionary). That will enable both faster iteration and threading. If you refactor for NativeArray or NativeHashmap then you will be able to use easier and safe threading with IJobParallerFor and maybe even Burst compiler (for unmanaged data only).
Sidenote: All Unity.Collections types are very slow to access from the main thread so plan ahead to limit this. It’s because those containers are optimized for job systems / dots specifically.