silenceheaven Posted March 23, 2018 Posted March 23, 2018 I have around 32 reactions, and from profiling it seems that in \IPS\Content\Reaction::isLikeMode() it was hanging up there for 1ms, but spread across a large amount of calls for each reaction for each post, it seems to be causing some major delays. Replacing it with this has seemed to have solved the issue, I hope I didn't break anything! public static $isLikeMode = NULL; /** * Is Like Mode * * @return bool */ public static function isLikeMode() { if ( static::$isLikeMode === NULL ) { $i = 0; foreach( static::roots() AS $row ) { if ( $row->_enabled !== FALSE ) { $i++; } } static::$isLikeMode = ( $i == 1 ); } return static::$isLikeMode; } public static $icons = array(); /** * Get Icon * * @return \IPS\File */ public function get__icon() { if ( empty( static::$icons[ $this->id ] ) ) { static::$icons[ $this->id ] = call_user_func_array( 'parent::get__icon', func_get_args() ); } return static::$icons[ $this->id ]; } Could something like this be included, as having it call roots() dozens of times, even if its going to the cache backend, is wasted cycles. Thanks!
TSP Posted March 23, 2018 Posted March 23, 2018 Did you mean 1 millisecond or something else? Because 1 ms in total for before your potential improvements really isn't a lot in isolation. Either way, if it improves performance and doesn't have any other disadvantages I'm personally all for it, so I hope this gets reviewed by the staff.
silenceheaven Posted March 23, 2018 Author Posted March 23, 2018 5 minutes ago, TSP said: Did you mean 1 millisecond or something else? Because 1 ms in total for before your potential improvements really isn't a lot in isolation. Either way, if it improves performance and doesn't have any other disadvantages I'm personally all for it, so I hope this gets reviewed by the staff. From xprofile, it has a decent amount of calls and each one was 1ms for a total of 50ms, but from it looks like, get__icon was causing over 500 calls, with a total time of 60ms. I might be wrong in the solution but there is an issue happening due to the large number of reactions, at least on my server. There also seems to be __get calls on reactions, 6000 of them with a total time of 66ms. This is on a single thread page too.
Daniel F Posted March 23, 2018 Posted March 23, 2018 Fair point. I have raised an internal discussion about this:)
Daniel F Posted March 23, 2018 Posted March 23, 2018 BTW, I have a better fix for the first issue;) There's no need for the static variable at all. We're going to treat it similar like the advertisements and announcements and create a setting which stores if it's likeMode or not:) This way it won't need to iterate over the elements at all except when we set and rebuild the setting when a reaction is added, deleted,enabled or disabled:)
bfarber Posted March 23, 2018 Posted March 23, 2018 Thanks for the feedback - we will look at this for 4.3.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.