discord-php / DiscordPHP

An API to interact with the popular messaging app Discord
MIT License
975 stars 236 forks source link

replace Role::permissions setter with getter to save up memory #1175

Closed SQKo closed 10 months ago

SQKo commented 10 months ago

To optimize Role object, its permission values wont be created unless manually get. I have tested this to lower the memory usage from 20 MB to 18 MB and faster init time in my Bot.

Also a new practice that should be done: When there is a fillable that is handled with custom attribute mutator, the method should be called instead of the magic property, right now this should only apply to the same class e.g. $this->icon_hash is override by $this->getIconHashAttribute() so the Role class should always use $this->getIconHashAttribute() instead of the $this->icon_hash. Does not apply to object instances e.g. $role->icon_hash should stay.

Not fully tested.