Simple-storage limitations and startup performance

4 views
Skip to first unread message

David Bruant

unread,
Mar 17, 2016, 7:22:51 AM3/17/16
to mozilla-la...@googlegroups.com
Hi,

This story begins with an addon I'm working on [1]. Among other things,
the addon stores credentials (... used to and will again soon...) in the
simple-storage. I've had 2 problems being reported to me that seem related:
1) for some people (all on OSX from the reports I received), the addon
acts as if there was no credentials
2) the addon slows Firefox startup down significantly (to the point
where a user decided to uninstall the addon)

Reading the simple-storage code [2], I discovered a few things :
a) File read errors are silently swallowed without even a warning in the
console (there is an interesting comment on that matter)
*
https://github.com/mozilla/addon-sdk/blob/3527a27ac240c1a5b7fde68af94e00a8e69c545d/lib/sdk/simple-storage.js#L109-L111
*
https://github.com/mozilla/addon-sdk/blob/3527a27ac240c1a5b7fde68af94e00a8e69c545d/lib/sdk/simple-storage.js#L55-L57
*
https://github.com/mozilla/addon-sdk/blob/3527a27ac240c1a5b7fde68af94e00a8e69c545d/lib/sdk/simple-storage.js#L155
b) Doing `const storage = require("sdk/simple-storage").storage`
triggers blocking I/O at startup
*
https://github.com/mozilla/addon-sdk/blob/3527a27ac240c1a5b7fde68af94e00a8e69c545d/lib/sdk/simple-storage.js#L30
*
https://github.com/mozilla/addon-sdk/blob/3527a27ac240c1a5b7fde68af94e00a8e69c545d/lib/sdk/simple-storage.js#L102
c) There is a write happening on disk every 5mins (by default) even if
no change occured

The problem 1) that I face is certainly related to a). This, in an of
itself, means that I won't be using simple-storage anymore as my users
face a problem I am unarmed to work against (they cannot even send me a
screenshot of the browser console).

Problem 2) may be related to b). This line of course is super
easy/natural to write and has consequences it probably shouln't have. It
would be possible to rewrite simple-storage as a Proxy [3] and wait to
do the blocking I/O only on first property access (and lazily write only
when a property is changed instead of forcing it every 5 minutes).
However, I also realize that problem 2) may be also related to the
CommonJS loader which, I imagine is doing sequential blocking I/O which
isn't fantastic at startup.

Would you have advice on how to measure the impact of the addon on
startup perf? and advice on how to improve it if loading CommonJS module
indeed does have an impact on performance?

Thanks,

David

[1] https://github.com/DavidBruant/Twitter-Assistant
[2]
https://github.com/mozilla/addon-sdk/blob/master/lib/sdk/simple-storage.js
[3]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
Reply all
Reply to author
Forward
0 new messages