Measure Performance

Polaris provides a way to measure the performance of your application. You can use the PolarisService to create instruments that measure the time it takes to complete a specific operation.

export class GridComponent {
  async onSort() {
    // measure render time
    const instrument = inject(PolarisService).getInstrument('grid-sort');
    try {
      await sort();
      requestAnimationFrame(() => instrument.done());
    } catch (error) {;

Let's review the code above.

  • First, we inject the PolarisService into our component.
  • Then, we get an instrument by calling getInstrument with a unique name.
  • Next, we start the instrument.
  • Then, we await the sort operation.
  • We use requestAnimationFrame to ensure the sort operation has completed, and then we invoke the done() method on the Instrument.
  • If the sort operation fails, we invoke the fail() method on the Instrument.