New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GM_setValue() can be slow #2197

Closed
ArkadiuszMichalski opened this Issue Jun 11, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@ArkadiuszMichalski

ArkadiuszMichalski commented Jun 11, 2015

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?

Edit:
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

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Aug 2, 2016

Collaborator

I re-wrote (because I couldn't find my previous version) a benchmark for testing GM_*Value performance: https://gist.github.com/arantius/3dc011a041e6205648fcddb7131af085

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

Collaborator

arantius commented Aug 2, 2016

I re-wrote (because I couldn't find my previous version) a benchmark for testing GM_*Value performance: https://gist.github.com/arantius/3dc011a041e6205648fcddb7131af085

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

@arantius

This comment has been minimized.

Show comment
Hide comment
@arantius

arantius Aug 2, 2016

Collaborator

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.

Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment