Conversation
| // Artificial slowdown for benchmark testing | ||
| const factoryStart = Date.now(); | ||
| while (Date.now() - factoryStart < 50) { | ||
| Math.random() * Math.random(); | ||
| } |
There was a problem hiding this comment.
Artificial 50ms delay shouldn't be in production code - will cause significant performance degradation on every middleware initialization.
| // 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.| // Artificial slowdown for benchmark testing | ||
| const middlewareStart = Date.now(); | ||
| while (Date.now() - middlewareStart < 30) { | ||
| Math.random() * Math.random(); | ||
| } |
There was a problem hiding this comment.
Artificial 30ms delay shouldn't be in production code - will execute on every single request, severely impacting application performance.
| // 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.There was a problem hiding this comment.
⚠️ 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
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:
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
createNextMiddleware.tsfile requires immediate attention - all artificial delays must be removed before mergingImportant Files Changed
Last reviewed commit: 2349f92
Context used:
dashboard- Remove console.log statements and debug logging from production code before merging. (source)