Le 21/02/2013 19:17, Fabrice Desre a écrit :
> On 02/21/2013 06:54 AM, Axel Hecht wrote:
>
>> That does sound like unfortunate API design, too? In particular if I
>> read the post you replied to, "you shouldn't expect that getting the
>> frequency to be fast" sounds like "doh, should've done that api async to
>> start with".
> Or it can also just be bug on the platform side. We fixed a bunch of
> IPC-related perf issues when working on the app startup times for instance.
>
> For the fmradio API, I see no reason to not be able to cache the current
> frequency value in the content process to speed this up.
and update it anytime the actual frequency changes of course (to avoid
having an invalid cached value). That could work.
Of course, you have to do that for every "fake" data-properly. The
FMRadio API has 5 or 6 of them. Do we have a list all such cases in
other APIs somewhere? (that could be useful for perf improvements)
Also, not all apps use the "frequency" property, so maybe we want to
have this cache+update setup only for apps that do, so create this setup
lazily on first access or something. That could work too.
Note that even in the lazy-tracking setup, there is some loss. For
instance, maybe the app will read the frequency property (that's
unlikely for this property, but that could be the case for another
property in another app) only once and never read it again, but cache
consistency has to be maintained regardless of whether the value is
actually read, so the main Gaia process may end up spending an absurd
amount of time to uselessly updating cached values of different apps.
All of that setup and work for the sake of... frequency being a property?
> David will probably disagree with any api design that is not using
> promises, but having a simple "frequency" property and an
> onfrequencychanged event looks even better to me.
Just to clarify my position, this is not about promises; this is about
abstracting correctly. Having a "frequency" property is misleading as it
gives the impression that the property is easy and quick to get.
But that's a wrong abstraction: the FM radio is a remote resource. It's
only natural to consider that any access to it is asynchronous. I think
promises are a really good abstraction for these cases, but others
prefer callbacks [1], that's cool too.
What I disagree with is any API design that pretends remote things to be
local.
As I described above, the implementation has to pay the price of faking
something remote as local. Whether it's a blocking direct access (as
today) or a complex cache+update setup which has some loss and which
scalability has yet to be proven. We can also not update the cache and
perf will be fine, but at the cost of reliability.
Pretending that something remote is local has a cost somewhere.
Abstracting something remote as accessed asynchronously has a cost...
for developers. But as asyncStorage and so many other DOMRequest-based
APIs have proven, Gaia developers survived and from what I've read of
Gaia, the Pyramids of Doom [2] haven't grown very high... (or "very
right" maybe I should say).
And an async abstraction has no runtime nor reliability cost. No need to
cache+update, people just get the value as they need it. If they want to
implement a cached value, they can do it themselves with accessing the
value once at startup and and update when the event occur (as long as
the value is provided as part of the event?). But if authors don't want
the cache mechanism, they shouldn't have to pay the price for it in my
opinion.
David
[1]
https://github.com/mozilla-b2g/gaia/blob/master/shared/js/async_storage.js
[2]
http://calculist.org/blog/2011/12/14/why-coroutines-wont-work-on-the-web/