Skip to content

test: bench mark#1057

Open
ErnestM1234 wants to merge 2 commits intomainfrom
e/next/test-bench-failures
Open

test: bench mark#1057
ErnestM1234 wants to merge 2 commits intomainfrom
e/next/test-bench-failures

Conversation

@ErnestM1234
Copy link
Copy Markdown
Contributor

@ErnestM1234 ErnestM1234 commented Feb 28, 2026

Greptile Summary

This PR adds artificial delays totaling 80ms (50ms during initialization + 30ms per request) to the Next.js middleware for benchmarking purposes. These delays are implemented as busy-wait loops in production code paths.

Major issues:

  • Artificial slowdowns will execute in production, causing severe performance degradation
  • 30ms delay runs on every single middleware request
  • 50ms delay runs on every middleware initialization
  • Violates the project's rule against leaving debug/test code in production

If benchmarking is needed, these delays should be implemented in a test environment or feature-flagged, not hardcoded in the production middleware.

Confidence Score: 0/5

  • This PR is not safe to merge - it introduces critical performance degradation in production
  • Score reflects that the PR adds hardcoded artificial delays (80ms total per request) directly into production middleware code, which will severely impact application performance for all users
  • The createNextMiddleware.ts file requires immediate attention - all artificial delays must be removed before merging

Important Files Changed

Filename Overview
packages/next/src/middleware-dir/createNextMiddleware.ts Added artificial delays (50ms + 30ms per request) for benchmark testing that will severely degrade production performance

Last reviewed commit: 2349f92

Context used:

  • Rule from dashboard - Remove console.log statements and debug logging from production code before merging. (source)

@ErnestM1234 ErnestM1234 requested a review from a team as a code owner February 28, 2026 00:20
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +51 to +55
// Artificial slowdown for benchmark testing
const factoryStart = Date.now();
while (Date.now() - factoryStart < 50) {
Math.random() * Math.random();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artificial 50ms delay shouldn't be in production code - will cause significant performance degradation on every middleware initialization.

Suggested change
// Artificial slowdown for benchmark testing
const factoryStart = Date.now();
while (Date.now() - factoryStart < 50) {
Math.random() * Math.random();
}

Context Used: Rule from dashboard - Remove console.log statements and debug logging from production code before merging. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/next/src/middleware-dir/createNextMiddleware.ts
Line: 51-55

Comment:
Artificial 50ms delay shouldn't be in production code - will cause significant performance degradation on every middleware initialization.

```suggestion
```

**Context Used:** Rule from `dashboard` - Remove console.log statements and debug logging from production code before merging. ([source](https://app.greptile.com/review/custom-context?memory=ea076fa4-7856-4d31-9266-35f86e49f4b6))

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +157 to +161
// Artificial slowdown for benchmark testing
const middlewareStart = Date.now();
while (Date.now() - middlewareStart < 30) {
Math.random() * Math.random();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Artificial 30ms delay shouldn't be in production code - will execute on every single request, severely impacting application performance.

Suggested change
// Artificial slowdown for benchmark testing
const middlewareStart = Date.now();
while (Date.now() - middlewareStart < 30) {
Math.random() * Math.random();
}

Context Used: Rule from dashboard - Remove console.log statements and debug logging from production code before merging. (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/next/src/middleware-dir/createNextMiddleware.ts
Line: 157-161

Comment:
Artificial 30ms delay shouldn't be in production code - will execute on every single request, severely impacting application performance.

```suggestion
```

**Context Used:** Rule from `dashboard` - Remove console.log statements and debug logging from production code before merging. ([source](https://app.greptile.com/review/custom-context?memory=ea076fa4-7856-4d31-9266-35f86e49f4b6))

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Middleware Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: ca164ab Previous: 3047e10 Ratio
gt-next > unit > middleware: factory creation latency > createNextMiddleware() (mean) 49.979744909090876 ms (±0.054) 0.043370529881169274 ms (±0.0191) 1152.39
gt-next > unit > middleware: per-request execution latency > default locale request (/) (mean) 80.04092680000011 ms (±0.1717) 0.2539664464195048 ms (±0.0674) 315.16
gt-next > unit > middleware: per-request execution latency > non-default locale request (/fr) (mean) 80.05384019999993 ms (±0.1912) 0.4492701060197664 ms (±0.0715) 178.19
gt-next > unit > middleware: per-request execution latency > nested route (/fr/about) (mean) 80.0215205999998 ms (±0.1482) 0.43514151652173894 ms (±0.0460) 183.90
gt-next > e2e > middleware: redirect-chain-fr-about > ttfb 46.89999999999418 ms 19.099999999976717 ms 2.46
gt-next > e2e > middleware: redirect-chain-fr-about > domContentLoaded 58.70000000001164 ms 29.79999999998836 ms 1.97
gt-next > e2e > middleware: cold-navigation-about > ttfb 42.5 ms 10.700000000011642 ms 3.97
gt-next > e2e > middleware: cold-navigation-about > domContentLoaded 52.20000000001164 ms 20.29999999998836 ms 2.57

This comment was automatically generated by workflow using github-action-benchmark.

CC: @generaltranslation/core

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.

1 participant