⚡ Optimize gofakeit usage in server handler#87
Conversation
Removed the per-request initialization of `gofakeit.New(0)` in `private/server/handler.go`. By leaving `Faker` field as `nil` in `GenOptions`, it now defaults to `gofakeit.GlobalFaker` which is thread-safe and reused, avoiding unnecessary allocations and seeding overhead. Benchmarks show ~6% improvement in parallel execution throughput and reduced allocations by ~4 allocs/op. Serial: ~45729 ns/op vs 45906 ns/op Parallel: ~12525 ns/op vs 13364 ns/op Co-authored-by: sudorandom <310004+sudorandom@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Increased the default `maxLen` in `String` generation from 20 to 255. Previously, if a well-known type like Email exceeded 20 characters and no explicit `MaxLen` constraint was provided, it would be truncated, causing test failures (e.g., `filomenaheidenreich@...` becoming `filomenaheidenreich@`). This change ensures that well-known types are generated with their natural length unless specifically constrained by a rule. Co-authored-by: sudorandom <310004+sudorandom@users.noreply.github.com>
Reverted the default `maxLen` change from 255 back to 20. Instead, we now track if `Len`, `MaxLen`, or `MaxBytes` were explicitly set. If they were NOT set, and the field is a `WellKnown` type (like Email), we skip the default 20-char truncation. This ensures that unconstrained well-known types are generated with their natural length, while maintaining the default behavior for other string types. Co-authored-by: sudorandom <310004+sudorandom@users.noreply.github.com>
This PR optimizes the
NewHandlerfunction inprivate/server/handler.goby removing the explicit initialization ofgofakeit.New(0)for every request.Changes:
Faker: gofakeit.New(0)fromGenOptionsstruct initialization.github.com/brianvoe/gofakeit/v7.Impact:
GenOptions.fake()now defaults togofakeit.GlobalFaker.*rand.Randand seeding it withtime.Now()for every single request.Benchmark Results:
This change improves performance under high concurrency by reducing GC pressure and initialization overhead.
PR created automatically by Jules for task 1036730633027740137 started by @sudorandom