#Detecting property changes on a large number of instances efficiently

1 messages · Page 1 of 1 (latest)

final slate
#

I have X number of instances that can come in 2 forms in an array of instances and as descendants of an instance. I want to detect changes to their properties on runtime in an efficient way. I would ideally like behavior like this fake example: "Instance.DescendantChanged:Connect(...)" (This example can't be applied to the array). I would like to avoid running a check on all the instances on every frame.
Due to memory concerns, I would also like to avoid connecting events on all the instances.
Keeping track of objects that are prone to changes and only checking them is also not an option

brazen dagger
#
local function onChanged(property)
    print(property)
end

for index, instance in instances do
    instance.Changed:Connect(onChanged)
end

or

for index, instance in instances do
    instance.Changed:Connect(function(property)
        print(instance.Name, property. instance[property])
    end)
end
final slate
#

"Due to memory concerns, I would also like to avoid connecting events on all the instances."

#

This would take up mememory for every instance

#

Unlike a singular event based system

#

if collectionservice had a .Changed event this would make my life so easy

#

please, correct me if my memory concerns are unfounded

brazen dagger
#

only other way is to force the thing changing the property to use a function in a module

#
local modules = {}

function module.SetProperty(instance, index, value)
    instance[index] = value
    print("Changed")
end

return module
final slate
#

Yeah

#

I'm currently doing some perfomance to check how the memory is affected

brazen dagger
#

then who ever sets the property does

module.SetProperty(Part, Position, Vector3.new())
final slate
brazen dagger
#

yer same thing

#

that would be the only other way i can think of

final slate
#

I cannot impose the use of the setter function

brazen dagger
#

then the next best thing is #1219701168192753786 message

final slate
#

Yeah

#

On a huge map you just see a mem increase of around 20 ~ mb

brazen dagger
#

well 20mb is ok

#

most people have more then 4GB

final slate
#

its a 30mb mem increase

#

acceptable i guess

long yacht
brazen dagger
# long yacht 3gb I’d say

3gb is a strange amount of ram to have because most who build a PC would want dual channel setup and you can't have 3gb with dual channel because you can't buy 2 1.5gb sticks

long yacht
#

Since the context is around that

brazen dagger
#

To have 3gb you would need to do 1 + 1 + 1 GB or 2 + 1 GB and both of these configurations are silly