GM_setValue() can be slow #2197

ArkadiuszMichalski opened this Issue Jun 11, 2015 · 2 comments


None yet

2 participants


Hi, I see that function GM_setValue() can hang browser for short time, but its noticable.

I made on page some timer with output to DIV elapsed milisecond (update with setInterval and 100ms). After this I run GM_setValue() in loop 14 times (saving only small numbers as string, like 3.14+"") and see that my timer is freeze and scrolling page too. But this can be easy fixed, just check if new value is different than old value taked by GM_getValue(), and if yes then invoke GM_setValue(), in other case don't do this.

Its normal that GM_setValue() takes much more cost than GM_getValue()? If yes then cold you somehow optimized it out-of the box?

Get some time to compare this two method (all in ms)
GM_getValue(): 9, 13, 12, 14, 15
GM_setValue(): 398, 330, 357, 315, 371

@ArkadiuszMichalski ArkadiuszMichalski changed the title from GM_setValue() my hang browser to GM_setValue() may hang browser Jun 11, 2015
@arantius arantius changed the title from GM_setValue() may hang browser to GM_setValue() can be slow Aug 2, 2016
@arantius arantius added this to the 3.9 milestone Aug 2, 2016
arantius commented Aug 2, 2016

I re-wrote (because I couldn't find my previous version) a benchmark for testing GM_*Value performance:

As noted in that source, I'm currently seeing set take roughly 30ms, while get takes roughly a half of one ms.

arantius commented Aug 2, 2016

After a few PRAGMA changes, I'm getting:

set * 10 = 106.3 ms total, 10.63 ms each
get * 10 = 6.39 ms total, 0.64 ms each
mixed * 10 = 65.71 ms total, 6.57 ms each
set * 50 = 158.44 ms total, 3.17 ms each
get * 50 = 41.09 ms total, 0.82 ms each
mixed * 50 = 200.08 ms total, 4 ms each
set * 100 = 265.02 ms total, 2.65 ms each
get * 100 = 73.55 ms total, 0.74 ms each
mixed * 100 = 369.18 ms total, 3.69 ms each

Get is unchanged, set is down around 3ms, which is a huge improvement. There's a chance for data loss as the changes involve doing less work on disk and more in memory, but historically (pre-sqlite-storage) GM_setValue data was guaranteed to be lost on a Firefox crash (or power outage or similar), so I'm comfortable with that tradeoff.

@arantius arantius added a commit that closed this issue Aug 2, 2016
@arantius arantius Increase GM_setValue() performance.
By optimizing for speed over reliability.  Generally by moving things from disk to memory.

Fixes #2197
@arantius arantius closed this in f75045f Aug 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment