vinum-team / Vinum

A modern reactive state management library for correctness and speed.
MIT License
16 stars 1 forks source link

Allow Certain State structs to return constants if they always evaluate to a constant #45

Closed xiyler closed 5 months ago

xiyler commented 6 months ago

It could be worthwhile to look into make certain state creators (Most notably Map) return a constant if its 100% verified that it will always return that constant.

If we also applied the idea of #44 on state creators, we could potentially have something like this...

local IS_BAD = true

local result = Map(IS_BAD, {
   default = "This should be bad"
}) 

... to be optimized into something simple like this:

local is_BAD = true
local result = "This should be bad"
xiyler commented 6 months ago

This could also work on something like Derived if we can verify that its dependencies aren't dynamic (every Derived update doesn't change the dependency tree), and these dependencies are constants.

xiyler commented 6 months ago

Deferred to 0.5

xiyler commented 5 months ago

It's currently hard to evaluate whether an state object will always evaluate to constant considering dynamic dependencies are supported.