Sleitnick / AeroGameFramework

AeroGameFramework is a Roblox game framework that makes development easy and fun. The framework is designed to simplify the communication between modules and seamlessly bridge the gap between the server and client.
https://sleitnick.github.io/AeroGameFramework/
MIT License
215 stars 57 forks source link

Run Init async and use promises to await completion #181

Closed Sleitnick closed 4 years ago

Sleitnick commented 4 years ago

Currently, Init methods are executed synchronously to guarantee they're all completed before Start methods are executed.

To improve startup speed, it might be better to run all Init methods asynchronously and then await them as promises before moving onto the Start methods.

Because all Init methods are intrinsically self-isolated (by practice, they should never be talking to other modules in the framework except for declaring references), there should be no side-effects of such a change, except for the negation of the existing __aeroOrder flag to control initialization order. It's possible that __aeroOrder could still be respected by guaranteeing the order if explicitly set. In other words, modules with __aeroOrder set would still act in synchronous fashion, whereas modules without the flag set would all execute at the same time together.

Example:

local inits = {}
for _,service in ipairs(serviceTables) do
    table.insert(inits, Promise.Async(function(resolve, reject)
        InitService(service)
        resolve()
    end))
end
Promise.All(inits):Await()
MrAsynchronous commented 4 years ago

I don't see a downside to this. This would be extremely beneficial to reducing load times in Aero-dependent games.

OverHash commented 4 years ago

Perhaps Aero should run __aeroOrder ones first, then run all the rest asynchronously. This would get the bost of both worlds. Users that never use __aeroOrder will see these reduced load-times.

Sleitnick commented 4 years ago

I'm going to close this for now. The minor performance gain is not really worth implementing this at this time.