Object:SetPropertyChangedEventMode()

Currently, .Changed and :GetPropertyChangedSignal() events for Objects are fired even if theres no listeners to them, this causes major performance penalties for heavy operations considering these events do alot of work behind the scenes to calculate cascading event chains to pass as string params to .Changed callbacks and whatnot

My proposed solution is to add a method to Object named :SetPropertyChangedEventMode(mode: Enum.PropertyChangedEventMode), and an enum called PropertyChangedEventMode.

PropertyChangedEventMode will contain these members:

  • Never: All property changes will never fire a changed event
  • NeverTransform: All property changes whos datatypes are Vector3, Vector2 or CFrame will never fire a changed event
  • Always: All property changes will fire a changed event

Checking of PropertyChangedEventMode should occur directly inside the __newindex closure of the Object metatable, preferably before any significant calculations are to be done.

Note that this mode is only for firing of events for lua script signals, if any internal stuff uses changed events idk keep it (probably shouldnt anyway though)

PropertyChangedEventMode.Never should always have checking priority above NeverTransform to prevent unecessary calculations

The seldom use of Changed events should make this a fairly good change, since it means users can gain performance benefits for heavy operations for 0 cost

2 Likes