Skip to content

Conversation

@RafaelGSS
Copy link
Owner

@RafaelGSS RafaelGSS commented Nov 16, 2025

Summary

Adds optional Dead Code Elimination (DCE) detection to help identify benchmarks that may be producing inaccurate results due to JIT optimization. When enabled, the system measures a baseline (empty function) and compares each benchmark against it to detect suspiciously fast benchmarks that may have been optimized away.

image

Motivation

When benchmarking JavaScript code, the JIT compiler can sometimes optimize away the actual work being measured, especially if:

  • The result of a computation is never used
  • Variables are created but never accessed
  • Operations have no observable side effects

This leads to misleading benchmark results where code appears to run much faster than it would in a real-world scenario.

Changes

New Plugin: DeadCodeEliminationDetectionPlugin

  • Measures baseline performance (empty function)
  • Compares each benchmark timing against the baseline
  • Warns when benchmarks run suspiciously fast (< 10x slower than baseline by default)
  • Configurable threshold via dceThreshold option

Suite Options

  • detectDeadCodeElimination (boolean, default: false) - Enable DCE detection
  • dceThreshold (number, default: 10) - Threshold multiplier for warnings

Behavior

  • Opt-in feature: DCE detection is disabled by default to maintain backward compatibility
  • When enabled, V8NeverOptimizePlugin is automatically disabled to allow V8 optimizations to occur naturally
  • Only works in ops mode (not time mode) and when not using worker threads

Testing

  • Added 7 comprehensive unit tests for DeadCodeEliminationDetectionPlugin
  • All tests passing
  • Three example files demonstrating usage

Documentation

  • Updated README.md with comprehensive DCE detection section
  • Added configuration examples
  • Updated TypeScript definitions in index.d.ts

Breaking Changes

None - This is an opt-in feature that defaults to false.

@RafaelGSS RafaelGSS marked this pull request as ready for review December 17, 2025 13:48
@RafaelGSS RafaelGSS force-pushed the add-dce-detection branch 3 times, most recently from 226d536 to 73cef40 Compare December 17, 2025 14:07
@RafaelGSS
Copy link
Owner Author

PTAL @H4ad @jdmarshall - Planning to land it today.

Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
@RafaelGSS RafaelGSS merged commit 2e2a6be into main Dec 17, 2025
6 checks passed
@RafaelGSS RafaelGSS deleted the add-dce-detection branch December 17, 2025 21:06
@jdmarshall
Copy link
Collaborator

I wonder if there is space for a diagnostic mode here. I might add it to Faceoff if you don’t think it’s appropriate for your target demographic.

Should there be a flag that forces this mode and scans for contention as discussed in #85

@RafaelGSS
Copy link
Owner Author

I guess the ttest mode would fix the #85.

@jdmarshall
Copy link
Collaborator

My suspicion is that sometimes it will detect the issue, but sometimes not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants