RE: [PerformanceTimeline] API/WebIDL related feedback

On Fri, Aug 23, 2013 at 5:31 AM, Nic Jansma <nic@nicj.net> wrote:
>
> One of the original reasons for only exposing the .getEntries() family of functions (which return copies
> of the array) vs. a performance.entries array that the user can directly access, is that the PerformanceTimeline
> array may be changing at any point in time.  Entries can be added to the end or middle of the array, or removed
> entirely both by async browser events (eg. new ResourceTimings complete) or by userland (eg UserTiming's
> clearMarks() is called).
>
> What we wanted to avoid was making it easy for developers to mistakenly blindly iterate over an array that
> could be modified underneath them.  Having new entries added to the end of the array probably won't cause
> problems with most for loops, but PerformanceTimeline-participating events could either remove entries from
> the array or even add PerformanceEntrys in the middle of the array.  For example, ResourceTimings don't get
> added to the array until they complete, but since the PerformanceTimeline array is sorted by startTime, new
> entries could suddenly appear in the "middle" of the array before current the last event.  This could lead to
> all sorts of problems if someone is just blindly iterating over the array with a for (...) loop.
>
> For these reasons, we chose to simplify things and only expose the .getEntries() family, which return static
> copies of the PerformanceTimeline at-that-point-in-time that will never change.

We had updated the spec after our TPAC 2011 discussion where we had come to the same conclusion as Nic (ACTION-74: Performance Timeline needs to be specific that getEntries returns a copy of the data, http://www.w3.org/2010/webperf/track/actions/74). The intention here being that we return a copy of the resources available at that moment in time, so one can compare the list of resources available at different moments in time. E.g., I can compare a snapshot of the list at load time and unload time to see what was dynamically added after load.

We should add a test case to check if performance.getEntries()[0] == performance.getEntries()[0] returns false.

Thanks,
Jatinder

Received on Tuesday, 27 August 2013 21:59:16 UTC