Skip to main content

Performance Utils API Reference

The Performance Utils provide cold start detection, streaming responses, and performance monitoring for edge applications.

ColdStartDetector

Cold start detection and optimization.

Constructor

Parameters:
  • options (object): Cold start detection options

Methods

isColdStart()

Check if current execution is a cold start.
Returns: Boolean indicating cold start

getColdStartCount()

Get number of cold starts.
Returns: Number of cold starts

reset()

Reset cold start counter.

PerformanceMonitor

Real-time performance monitoring.

Constructor

Parameters:
  • options (object): Performance monitoring options

Methods

start(label)

Start timing an operation.
Parameters:
  • label (string): Timer label
Returns: Timer identifier

end(label)

End timing an operation.
Parameters:
  • label (string): Timer label

getDuration(label)

Get duration of an operation.
Parameters:
  • label (string): Timer label
Returns: Duration in milliseconds

getMemoryUsage()

Get current memory usage.
Returns: Memory usage in bytes

getCpuUsage()

Get current CPU usage.
Returns: CPU usage percentage

StreamingResponse

Efficient streaming response handling.

Constructor

Methods

write(data)

Write data to stream.
Parameters:
  • data (string|Uint8Array): Data to write

end()

End the stream.

getReader()

Get stream reader.
Returns: ReadableStream reader

CompressionManager

Response compression utilities.

Constructor

Parameters:
  • options (object): Compression options

Methods

compress(response, options)

Compress a response.
Parameters:
  • response (Response): HTTP response
  • options (object): Compression options
Returns: Promise resolving to compressed response

shouldCompress(response)

Check if response should be compressed.
Parameters:
  • response (Response): HTTP response
Returns: Boolean indicating if compression should be applied

ResourceMonitor

Resource usage monitoring.

Constructor

Parameters:
  • options (object): Resource monitoring options

Methods

getCurrentUsage()

Get current resource usage.
Returns: Resource usage object

start()

Start resource monitoring.

stop()

Stop resource monitoring.

Type Definitions

ColdStartOptions

PerformanceMonitorOptions

CompressionOptions

ResourceUsage