Devan-Kerman / ARRP

A fabric api for creating resources and assets at runtime
Mozilla Public License 2.0
104 stars 27 forks source link

Threading conundrum #2

Closed Chocohead closed 4 years ago

Chocohead commented 4 years ago

I'm in the situation where I have potentially a significant number of runtime assets which are relatively slow to read which all need giving to RRP. With the way this is designed I would've thought the rrp_pre entrypoint would work, yet its implementation is just a serial loop in another thread. Whilst there is nothing wrong with this, it leaves me with a choice of three scenarios:

I have a feeling everything isn't designed with threading in mind (which is totally fine. it can be a pain to design for), but if speed is the goal to use this over Artifice it shouldn't be left taped on IMO. I have given it a little thought about possible solutions at least if you'd like some ideas:

There's probably an argument for an entirely threaded form of RuntimeResourcePack, maybe even using Semaphores to limit concurrent writes or just as a lazy way of de-threading calls (or a ReentrantReadWriteLock which would work for that task too), but maybe there's a point of diminishing returns eventually where it doesn't quite need to be that complicated. All food for thought in making the generation faster at least.

Devan-Kerman commented 4 years ago

using the same executor service won't work in the event a mod decides to wait on an async task for whatever reason. I should have used a lock, and for some reason didn't. I think rrp is in need a big upgrade though, since modders can't choose the priority of the resource pack, along with the inefficiencies of using String#format for templating, and then creating a byte array from that

Devan-Kerman commented 4 years ago

I've rewritten the whole thing from scratch, will commit soon:tm: once wiki is done, I think the threading is much better this time

Devan-Kerman commented 4 years ago

Well there you go, all done I think