@webruntime/performance
TypeScript icon, indicating that this package has built-in type declarations

1.61.4 • Public • Published

Lightning Web Runtime :: Performance

This package contains a utility for recording runtime performance.

Getting Started

Install:

npm install @webruntime/performance

Usage

Measuring

This package provides two functions for manually starting and ending performance time measurements and a typescript decorator for automatically recording the runtime of decorated class methods.

const { endMeasure, startMeasure } = require('@webruntime/performance');

function fib(n) {
    startMeasure(`fib-${n}`);
    let res = n === 1 || n === 2 ? 1 : fib(n - 1) + fib(n - 2);
    endMeasure(`fib-${n}`);
    return res;
}
import { Measure } from '@webruntime/performance';

class FibonacciCalculator {
    ...

    @Measure(n => `fib-${n}`)
    calculate (n: number) {
        return n === 1 || n === 2 ? 1 : fib(n-1) + fib(n-2);
    }
}

Collecting Measurements

This package does not currently log the timing measurements being recorded by the utility due to LWR not yet having a configurable logger. For now, users can use a PerformanceObserver.

const { PerformanceObserver } = require('perf_hooks');

const observer = new PerformanceObserver(observe);
observer.observe({
    entryTypes: ['measure'],
    buffered: false,
});

function observe(list) {
    const entries = list.getEntries();

    entries.forEach((entry) => {
        console.log(entry);
    });
}

Readme

Keywords

none

Package Sidebar

Install

npm i @webruntime/performance

Weekly Downloads

267

Version

1.61.4

License

MIT

Unpacked Size

180 kB

Total Files

16

Last publish

Collaborators

  • tconn
  • diervo
  • zhawtof
  • kjkimsfdc
  • lwc-admin