simplify: reduce duplication in declarative benchmark helpers#900
Merged
simplify: reduce duplication in declarative benchmark helpers#900
Conversation
- caseTokenMatches: return bool expression directly - boolEnv: collapse empty-string case into default, inline value var - medianInt/medianInt64: unify into generic median[T int | int64] - percentDelta/percentDelta64: unify into generic percentDelta[T int | int64] - maxFloat: replace manual loop with slices.Max Agent-Logs-Url: https://github.com/Kong/kongctl/sessions/ff84046f-b15a-41bd-9242-102e0c71741a Co-authored-by: rspurgeon <10521262+rspurgeon@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Kong/kongctl/sessions/ff84046f-b15a-41bd-9242-102e0c71741a Co-authored-by: rspurgeon <10521262+rspurgeon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Simplify code in benchmarks for clarity and maintainability
simplify: reduce duplication in declarative benchmark helpers
Apr 25, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the declarative benchmark helpers under test/benchmarks/declarative/ to remove small pockets of duplicated logic and simplify a few helper functions, improving readability and keeping behavior consistent.
Changes:
- Simplifies boolean helpers (
caseTokenMatches,boolEnv) by returning expressions directly / removing redundant switch cases. - Unifies duplicated
medianandpercentDeltahelpers via Go generics (int | int64) and updates call sites. - Replaces a manual max loop with
slices.Maxand ignores a Bubbletea test debug log file in.gitignore.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/benchmarks/declarative/main.go | Simplifies selector/env helpers and consolidates median/percentDelta logic using generics. |
| test/benchmarks/declarative/report.go | Simplifies maxFloat implementation by using slices.Max while preserving the empty-input guard. |
| .gitignore | Adds tea_debug.log to avoid committing Bubbletea debug logs generated during tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five redundant patterns in
test/benchmarks/declarative/identified and eliminated.Changes
caseTokenMatches— return boolean expression directly; drop wrappingif/return true/return falseboolEnv— mergecase "":intodefault(identical bodies); inlinevaluevariablemedianInt+medianInt64→median[T int | int64]— unified with Go generics; call sites infer typepercentDelta+percentDelta64→percentDelta[T int | int64]— same pattern;percentDelta64(...)call site updated topercentDelta(...)maxFloat— replace manual accumulator loop withslices.Max; empty-slice guard retained (panics on empty input)