Skip to main content
Profile JavaScript code to analyze performance bottlenecks with detailed function-level metrics and interactive visualizations.
Experimental WIP feature - functionality may change

Usage

porf profile [flags] script.js [title]

Examples

porf profile script.js

Arguments

script.js
string
required
JavaScript file to profile
title
string
Custom title for the profile report (defaults to filename)
porf profile benchmark.js "Sorting Algorithm Comparison"

How It Works

The profiler:
  1. Instruments code: Injects profiling hooks around function calls
  2. Executes: Runs your code while collecting timing data
  3. Processes: Analyzes performance metrics and builds visualizations
  4. Uploads: Sends data to profile.porffor.dev
  5. Displays URL: Provides link to interactive web report

Output

$ porf profile benchmark.js
Compiling...
Starting execution...
Running... Samples: 15234
Execution finished in 1234.56ms
Processing 15234 raw samples...
Filtered out 127 samples shorter than 0.01ms.
Building hierarchy from 15107 samples...
uploading...
https://profile.porffor.dev/abc123def456

Profile Report

The generated URL opens an interactive web page with:

Flame Graph

Visualizes the call stack and time spent in each function:
  • Width: Time spent in function (wider = more time)
  • Height: Call stack depth
  • Color: Differentiates between functions
  • Interactive: Click to zoom, hover for details

Bar Chart

Shows top 50 functions by total time:
  • Total time spent
  • Average time per call
  • Minimum time
  • Maximum time
  • Call count

Metadata

Profile information:
  • Porffor version
  • Runtime environment (Node.js version, browser)
  • Execution date/time
  • Total duration
  • Sample count

Profiling Options

-On
flag
Optimization level affects profile results
# Profile unoptimized code
porf profile -O0 script.js

# Profile optimized code (more realistic)
porf profile -O3 script.js
--parse-types
flag
Enable TypeScript parsing
porf profile --parse-types script.ts

Sample Filtering

The profiler filters very short samples:
  • Threshold: 0.01ms (configurable in source)
  • Reason: Reduce noise and improve visualization clarity
  • Impact: Ultra-fast function calls may not appear in flame graph but are counted in statistics

Understanding Results

Flame Graph Patterns

Functions taking significant time - optimization candidates
Many nested function calls - potential recursion or deep call chains
Function calling many sub-functions - coordination overhead
Most time in single function - optimize this function directly

Bar Chart Metrics

Total Time
metric
Cumulative time across all calls to this function
Average Time
metric
Mean time per function call
Min/Max Time
metric
Fastest and slowest individual calls
Count
metric
Number of times function was called

Example Workflow

1

Write code to profile

benchmark.js
function fibonacci(n) {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

function run() {
  for (let i = 0; i < 30; i++) {
    fibonacci(i);
  }
}

run();
2

Run profiler

porf profile benchmark.js "Fibonacci Benchmark"
3

Open profile URL

Click the generated URL to view interactive results
4

Analyze bottlenecks

  • Identify hot functions in flame graph
  • Check bar chart for most time-consuming functions
  • Note call counts and average times
5

Optimize

Make code changes based on insights
6

Re-profile

Compare new profile to measure improvements

Progress Indicator

While running, the profiler shows a spinner with sample count:
Running... Samples: 1523
Updates every 500ms during execution.

Internal Functions

Internal Porffor functions are marked differently in visualizations:
  • Compiler-generated functions
  • Built-in functions
  • Runtime helpers
These can be identified in the flame graph to distinguish your code from internal operations.

Performance Impact

Profiling adds overhead:
  • Function call instrumentation
  • Timing measurements
  • Sample collection
Typical overhead: 2-10x slower execution
Profile results show relative performance, not absolute runtime. Use for optimization guidance, not production benchmarking.

Optimization Tips

Based on profile results:
  • Optimize algorithm complexity
  • Reduce redundant calculations
  • Consider caching results
  • Reduce function call overhead
  • Inline small functions
  • Batch operations
  • Reduce loop iterations
  • Combine multiple calls
  • Use more efficient data structures
  • Investigate worst-case inputs
  • Optimize edge cases
  • Add fast paths

Sharing Profiles

Profile URLs are public and shareable:
# Profile is uploaded to:
https://profile.porffor.dev/<unique-id>

# Share this URL with team members

Comparison Workflow

# Before optimization
porf profile script.js "Before optimization"
# https://profile.porffor.dev/abc123

# After optimization
porf profile script.js "After optimization" 
# https://profile.porffor.dev/def456

# Compare both profiles side-by-side

Limitations

  • Only profiles function calls (not individual lines)
  • Adds execution overhead
  • Requires internet connection (uploads to profile.porffor.dev)
  • Short-lived functions (less than 0.01ms) may be filtered
  • Experimental feature, may have bugs

Privacy

Profile data includes:
  • Function names
  • Timing information
  • Call counts
  • System information (Porffor version, runtime)
  • Custom title
Does NOT include:
  • Function source code
  • Variable values
  • Personal information

Advanced Usage

porf profile -O3 --opt-types script.ts "Optimized version"

Troubleshooting

No samples collected

  • Script may not have any function calls
  • Execution too fast
  • Try more complex code

Upload failed

  • Check internet connection
  • Verify profile.porffor.dev is accessible
  • Try again later

Unexpected results

  • Profile with different optimization levels
  • Compare with manual timing using console.time()
  • Report issues on GitHub

Next Steps

Optimize Code

Apply insights and re-run

Debug Issues

Interactive debugging

Compile Optimized

Build native binary with optimizations

Understanding Optimization

Learn about optimization flags

Build docs developers (and LLMs) love