Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Please use Add*VarCache and not Get* when reading pref values in any even possibly warm code paths

66 views
Skip to first unread message

smaug

unread,
Feb 22, 2017, 6:18:40 AM2/22/17
to
Hi,

Preferences::GetBool is a slow hashtable lookup and has been showing up in performance profiles in many places.
Please use Preferences::AddBoolVarCache. Same with other pref types.
Or if the pref needs to be read just once, store the value in some static variable or so.



-Olli

Gijs Kruitbosch

unread,
Feb 22, 2017, 6:42:16 AM2/22/17
to
Related note: add*varcache uses a pref observer behind the scenes. Pref
observers always prefix-match, and the *varcache implementation doesn't
bother re-checking whether the pref for which it gets a notification
matches the one you requested a cache for. So if you have prefs
"blah.foo" and "blah.foo.bar", changing blah.foo.bar will write garbage
into your cache for blah.foo.

https://bugzilla.mozilla.org/show_bug.cgi?id=1208744

~ Gijs

smaug

unread,
Feb 22, 2017, 8:23:37 AM2/22/17
to Gijs Kruitbosch
Huh, that is a horrible bug.

Kris Maglione

unread,
Feb 22, 2017, 1:22:46 PM2/22/17
to smaug, dev-pl...@lists.mozilla.org
And in JS code, you can use XPCOMUtils.defineLazyPreferenceGetter for
the same reasons, and the same effect.

Gijs Kruitbosch

unread,
Feb 22, 2017, 5:43:14 PM2/22/17
to
Kit helpfully pointed out that this got fixed 6 months after I filed the
referenced bug, when Matt Woodrow ran into it with a different pref -
https://bugzilla.mozilla.org/show_bug.cgi?id=1267868 . So ignore my
caveat - pref caches should be working normally now 'even' where the
cached pref name is a string prefix of another pref name. :-)

~ Gijs

Masayuki Nakano

unread,
Feb 23, 2017, 4:11:18 AM2/23/17
to smaug, dev-pl...@lists.mozilla.org
Do you have any ideas of the cases we should use Add*VarCache?

For example, it's bad if using Get* when:

* every painting
* every mousemove
* every user input except mousemove
* every focus move
* every DOM change
* every page load

etc.

I wonder, if everybody uses Add*VarCache, doesn't it cause another
performance problem when a pref is changed?
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform


--
Masayuki Nakano <masa...@d-toybox.com>
Software Engineer, Mozilla

smaug

unread,
Feb 23, 2017, 5:31:49 AM2/23/17
to Masayuki Nakano
On 02/23/2017 11:10 AM, Masayuki Nakano wrote:
> Do you have any ideas of the cases we should use Add*VarCache?
>
> For example, it's bad if using Get* when:
>
> * every painting
possibly

> * every mousemove
probably

> * every user input except mousemove
well, touchmove is happening a lot too, and possibly wheel, so maybe cache should be used.
Writing a microbenchmark and profiling a bit shouldn't take more than couple of minutes and if the
Get* shows up in the profiles, perhaps worth to convert to Add*VarCache

> * every focus move
happens quite rarely, so maybe not needed

> * every DOM change
Definitely use cache

> * every page load
This happens rarely, so probably doesn't matter
0 new messages