Skip to content
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

Performance api improvements #709

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions api-reports/2_12.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15763,30 +15763,33 @@ Pbkdf2Params[SO] val salt = salt0
Performance[JC] def clearMarks(markName: String?): Unit
Performance[JC] def clearMeasures(measureName: String?): Unit
Performance[JC] def clearResourceTimings(): Unit
Performance[JC] def getEntries(): js.Dynamic
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Dynamic
Performance[JC] def getEntriesByType(entryType: String): js.Dynamic
Performance[JC] def getMarks(markName: String?): js.Dynamic
Performance[JC] def getMeasures(measureName: String?): js.Dynamic
Performance[JC] def mark(markName: String): Unit
Performance[JC] def measure(measureName: String, startMarkName: String?, endMarkName: String?): Unit
Performance[JC] def getEntries(): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByName(name: String, `type`: String?): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByType(entryType: String): js.Array[PerformanceEntry]
Performance[JC] def getMarks(markName: String?): js.Dynamic (@deprecated in 2.4.0)
Performance[JC] def getMeasures(measureName: String?): js.Dynamic (@deprecated in 2.4.0)
Performance[JC] def mark(markName: String): PerformanceMark
Performance[JC] def measure(measureName: String, startMarkName: String?, endMarkName: String?): PerformanceMeasure
Performance[JC] def navigation: PerformanceNavigation
Performance[JC] def now(): Double
Performance[JC] def setResourceTimingBufferSize(maxSize: Int): Unit
Performance[JC] def timing: PerformanceTiming
Performance[JC] def toJSON(): js.Dynamic
Performance[JC] def toJSON(): js.Object
PerformanceEntry[JC] def duration: Int
PerformanceEntry[JC] def entryType: String
PerformanceEntry[JC] def name: String
PerformanceEntry[JC] def startTime: Double
PerformanceEntry[JC] def toJSON(): js.Object
PerformanceMark[JC] def duration: Int
PerformanceMark[JC] def entryType: String
PerformanceMark[JC] def name: String
PerformanceMark[JC] def startTime: Double
PerformanceMark[JC] def toJSON(): js.Object
PerformanceMeasure[JC] def duration: Int
PerformanceMeasure[JC] def entryType: String
PerformanceMeasure[JC] def name: String
PerformanceMeasure[JC] def startTime: Double
PerformanceMeasure[JC] def toJSON(): js.Object
PerformanceNavigation[JC] def redirectCount: Int
PerformanceNavigation[JC] def toJSON(): js.Dynamic
PerformanceNavigation[JC] def `type`: Int
Expand All @@ -15809,6 +15812,7 @@ PerformanceResourceTiming[JC] def requestStart: Int
PerformanceResourceTiming[JC] var responseEnd: Int
PerformanceResourceTiming[JC] def responseStart: Int
PerformanceResourceTiming[JC] def startTime: Double
PerformanceResourceTiming[JC] def toJSON(): js.Object
PerformanceTiming[JC] def connectEnd: Double
PerformanceTiming[JC] def connectStart: Double
PerformanceTiming[JC] def domComplete: Double
Expand Down
20 changes: 12 additions & 8 deletions api-reports/2_13.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15763,30 +15763,33 @@ Pbkdf2Params[SO] val salt = salt0
Performance[JC] def clearMarks(markName: String?): Unit
Performance[JC] def clearMeasures(measureName: String?): Unit
Performance[JC] def clearResourceTimings(): Unit
Performance[JC] def getEntries(): js.Dynamic
Performance[JC] def getEntriesByName(name: String, entryType: String?): js.Dynamic
Performance[JC] def getEntriesByType(entryType: String): js.Dynamic
Performance[JC] def getMarks(markName: String?): js.Dynamic
Performance[JC] def getMeasures(measureName: String?): js.Dynamic
Performance[JC] def mark(markName: String): Unit
Performance[JC] def measure(measureName: String, startMarkName: String?, endMarkName: String?): Unit
Performance[JC] def getEntries(): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByName(name: String, `type`: String?): js.Array[PerformanceEntry]
Performance[JC] def getEntriesByType(entryType: String): js.Array[PerformanceEntry]
Performance[JC] def getMarks(markName: String?): js.Dynamic (@deprecated in 2.4.0)
Performance[JC] def getMeasures(measureName: String?): js.Dynamic (@deprecated in 2.4.0)
Performance[JC] def mark(markName: String): PerformanceMark
Performance[JC] def measure(measureName: String, startMarkName: String?, endMarkName: String?): PerformanceMeasure
Performance[JC] def navigation: PerformanceNavigation
Performance[JC] def now(): Double
Performance[JC] def setResourceTimingBufferSize(maxSize: Int): Unit
Performance[JC] def timing: PerformanceTiming
Performance[JC] def toJSON(): js.Dynamic
Performance[JC] def toJSON(): js.Object
PerformanceEntry[JC] def duration: Int
PerformanceEntry[JC] def entryType: String
PerformanceEntry[JC] def name: String
PerformanceEntry[JC] def startTime: Double
PerformanceEntry[JC] def toJSON(): js.Object
PerformanceMark[JC] def duration: Int
PerformanceMark[JC] def entryType: String
PerformanceMark[JC] def name: String
PerformanceMark[JC] def startTime: Double
PerformanceMark[JC] def toJSON(): js.Object
PerformanceMeasure[JC] def duration: Int
PerformanceMeasure[JC] def entryType: String
PerformanceMeasure[JC] def name: String
PerformanceMeasure[JC] def startTime: Double
PerformanceMeasure[JC] def toJSON(): js.Object
PerformanceNavigation[JC] def redirectCount: Int
PerformanceNavigation[JC] def toJSON(): js.Dynamic
PerformanceNavigation[JC] def `type`: Int
Expand All @@ -15809,6 +15812,7 @@ PerformanceResourceTiming[JC] def requestStart: Int
PerformanceResourceTiming[JC] var responseEnd: Int
PerformanceResourceTiming[JC] def responseStart: Int
PerformanceResourceTiming[JC] def startTime: Double
PerformanceResourceTiming[JC] def toJSON(): js.Object
PerformanceTiming[JC] def connectEnd: Double
PerformanceTiming[JC] def connectStart: Double
PerformanceTiming[JC] def domComplete: Double
Expand Down
34 changes: 27 additions & 7 deletions dom/src/main/scala/org/scalajs/dom/Performance.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.scalajs.js.annotation._
*/
@js.native
@JSGlobal
class Performance extends js.Object {
class Performance private[this] () extends js.Object {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot create objects of type Performance. Is this the correct way to forbid it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think we do this in other places as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is correct.


/** The Performance.navigation read-only property returns a PerformanceNavigation object representing the type of
* navigation that occurs in the given browsing context, like the amount of redirections needed to fetch the
Expand All @@ -28,29 +28,49 @@ class Performance extends js.Object {
*/
def timing: PerformanceTiming = js.native

def getEntriesByType(entryType: String): js.Dynamic = js.native
/** Returns an array of [[PerformanceEntry]] objects currently present in the performance timeline for a given type */
def getEntriesByType(entryType: String): js.Array[PerformanceEntry] = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are only a limited set of values that can be passed as an entryType I wonder if we should create a specific type for it.
https://developer.mozilla.org/en-US/docs/Web/API/PerformanceEntry/entryType

E.g. like InputType.
https://github.com/scala-js/scala-js-dom/blob/1a944e4863aaf52694e29e38fb2a174f351f2ceb/dom/src/main/scala-3/org/scalajs/dom/InputType.scala

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe I was wrong 😅

As the list of supported entries varies per browser and is evolving, this property allows web developers to check which are available.

https://developer.mozilla.org/en-US/docs/Web/API/PerformanceObserver/supportedEntryTypes


/** Is a jsonizer returning a json object representing the Performance object. */
armanbilge marked this conversation as resolved.
Show resolved Hide resolved
def toJSON(): js.Dynamic = js.native
def toJSON(): js.Object = js.native

@deprecated("No such API in the spec", "2.4.0")
def getMeasures(measureName: String = js.native): js.Dynamic = js.native

/** Removes all or specific [[PerformanceMark]] objects from the browser's performance timeline. */
def clearMarks(markName: String = js.native): Unit = js.native

@deprecated("No such API in the spec", "2.4.0")
def getMarks(markName: String = js.native): js.Dynamic = js.native

/** Removes all performance entries with an `entryType` of "resource" from the browser's performance timeline and sets
* the size of the performance resource data buffer to zero.
*/
def clearResourceTimings(): Unit = js.native

def mark(markName: String): Unit = js.native
/** Creates a named [[PerformanceMark]] object representing a high resolution timestamp marker in the browser's
* performance timeline.
*/
def mark(markName: String): PerformanceMark = js.native

def measure(measureName: String, startMarkName: String = js.native, endMarkName: String = js.native): Unit = js.native
/** Creates a named [[PerformanceMeasure]] object representing a time measurement between two marks in the browser's
* performance timeline.
*/
def measure(measureName: String, startMarkName: String = js.native,
endMarkName: String = js.native): PerformanceMeasure = js.native

def getEntriesByName(name: String, entryType: String = js.native): js.Dynamic = js.native
/** Returns an array of [[PerformanceEntry]] objects currently present in the performance timeline with the given name
* and type.
*/
def getEntriesByName(name: String, `type`: String = js.native): js.Array[PerformanceEntry] = js.native

def getEntries(): js.Dynamic = js.native
/** All [[PerformanceEntry]] objects currently present in the performance timeline. */
def getEntries(): js.Array[PerformanceEntry] = js.native

/** Removes all or specific [[PerformanceMeasure]] objects from the browser's performance timeline. */
def clearMeasures(measureName: String = js.native): Unit = js.native

/** sets the desired size of the browser's resource timing buffer which stores the "resource" performance entries. */
armanbilge marked this conversation as resolved.
Show resolved Hide resolved
def setResourceTimingBufferSize(maxSize: Int): Unit = js.native

/** Returns a DOMHighResTimeStamp representing the amount of milliseconds elapsed since the start of the navigation,
Expand Down
15 changes: 15 additions & 0 deletions dom/src/main/scala/org/scalajs/dom/PerformanceEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ package org.scalajs.dom
import scala.scalajs.js
import scala.scalajs.js.annotation._

/** Encapsulates a single performance metric that is part of the browser's performance timeline. */
@js.native
@JSGlobal
class PerformanceEntry extends js.Object {

/** The name for a performance entry. It acts as an identifier, but it does not have to be unique. The value depends
* on the subclass.
*/
def name: String = js.native

/** The first timestamp recorded for this performance entry. The meaning of this property depends on the value of this
* entry's [[entryType]].
*/
def startTime: Double = js.native
Comment on lines +22 to 25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec mentions that this returns a "DOMHighResTimestamp" https://w3c.github.io/performance-timeline/#dom-performanceentry

Is it worth it to make a type for https://www.w3.org/TR/hr-time-3/#dom-domhighrestimestamp

Copy link
Member

@armanbilge armanbilge Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't want an opaque type, since then you can't do numerical ops on it.

We could make a transparent type alias e.g. type DOMHighRestTimestamp = Double but it's a coin flip whether its documentation or obfuscation 😂


/** The duration of the performance entry. The meaning of this property depends on the value of this entry's
* [[entryType]].
*/
def duration: Int = js.native

/** The type of performance metric that this entry represents. */
def entryType: String = js.native

/** Returns a JSON representation of the [[PerformanceEntry]] object. */
def toJSON(): js.Object = js.native
}