Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
## 2025-05-10 - fmt.Sscanf is lenient, strconv.Atoi is strict
**Learning:** In Go, `fmt.Sscanf("%d")` parses digits until it encounters a non-digit character (e.g., `"2beta"` parses as `2`), while `strconv.Atoi` fails and returns `0` for the entire string. If you need the lenient parsing behavior of `fmt.Sscanf` for performance optimization, implement a custom byte-traversal loop to extract leading digits rather than relying on `strconv.Atoi` or regex, as it is over 10x faster and maintains exact functional parity.
**Action:** When replacing `fmt.Sscanf` for performance, always evaluate whether the leniency of the parser is being implicitly relied upon by the surrounding code.

## 2024-05-22 - Avoid strings.Split in hot loops
**Learning:** Using `strings.Split` to parse strings separated by a known single-byte delimiter causes unnecessary slice allocations, memory pressure, and slows down performance.
**Action:** When iterating over segments of a delimited string, use a `for` loop with `strings.Cut` to avoid intermediate slice allocations and improve parsing speed.
24 changes: 10 additions & 14 deletions internal/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,24 +832,20 @@ func parseLenientAtoi(s string) int {
// CompareVersions compares two semver strings
// Returns -1 if a < b, 0 if a == b, 1 if a > b
func CompareVersions(a, b string) int {
partsA := strings.Split(a, ".")
partsB := strings.Split(b, ".")
for a != "" || b != "" {
var partA, partB string

maxLen := len(partsA)
if len(partsB) > maxLen {
maxLen = len(partsB)
}

for i := 0; i < maxLen; i++ {
var numA, numB int
if i < len(partsA) {
// Bolt optimization: using a custom loop is ~14x faster than fmt.Sscanf
numA = parseLenientAtoi(partsA[i])
if a != "" {
partA, a, _ = strings.Cut(a, ".")
}
if i < len(partsB) {
numB = parseLenientAtoi(partsB[i])
if b != "" {
partB, b, _ = strings.Cut(b, ".")
}

// Bolt optimization: using a custom loop is ~14x faster than fmt.Sscanf
numA := parseLenientAtoi(partA)
numB := parseLenientAtoi(partB)

if numA < numB {
return -1
}
Expand Down
Loading