-
Notifications
You must be signed in to change notification settings - Fork 13
Description
As the status quo, the user marks and measures are globally buffered and need to be cleared manually with performance.clearMarks and performance.clearMeasures. In wild practice, this can be very awkward for applications or libraries that record repetitive series of operations: their marks and measures have to be prefixed to prevent from colliding from maybe overlapping async operations, and they must clear the marks and measures with prefixed names with performance.clearMarks and performance.clearMeasures after the operations complete.
If the marks and measures are not cleared correctly, they are likely to get memory leakages. This is not a very idiom JavaScript resource management pattern. It can be better if those buffered entries can be garbage collected once their contextual async operation is not referenced anymore.
This problem stands out on Node.js significantly. Node.js provides standard-compliant user timing API to allow applications or libraries to work with Web platforms seamlessly, whilst those applications or libraries are supposed to run code repetitively on the server-side.
If the user timing can be created under a contextual performance timeline, then this specific performance timeline can be referenced from the context of these async operations, like events, requests, etc. Once the context of these operations was not used anymore, all of them can be garbage collected cleanly. And there won't need the name prefixes for entries since they are not put into the global performance timeline and won't get overlapping with each other.
Conceptual usage:
addEventListener('an_event_name', event => {
const eventPerformance = new Performance('click event');
eventPerformance.mark('mark a');
asyncOperation()
.then(() => {
eventPerformance.measure('measure a', 'mark a');
logEntries(eventPerformance.getEntries());
// eventPerformance and their user timing can be GC-ed without manual clearance.
});
});