Skip to content
Draft
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 @@ -20,3 +20,7 @@
## 2026-05-27 - Reducing Allocations with bufio.Scanner
**Learning:** Parsing large embedded strings (like blocklists) using `strings.Split` creates a large slice of strings that persists until the loop finishes. This is inefficient for one-time map population.
**Action:** Use `bufio.Scanner` with `strings.NewReader` to process the string line-by-line. This minimizes temporary allocations and is significantly more memory-efficient for large text datasets.

## 2026-06-05 - Optimizing string parsing
**Learning:** Using bufio.Scanner for parsing strings in memory still requires allocating scanner structures and copying slices. A loop matching on newlines (`strings.IndexByte`) and slicing directly from the original string is significantly faster and requires zero extra allocations.
**Action:** Use index-based slicing instead of bufio.Scanner when extracting lines from embedded strings that are only parsed once.
15 changes: 10 additions & 5 deletions internal/core/passwords.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core

import (
"bufio"
_ "embed"
"strings"
"sync"
Expand All @@ -18,10 +17,16 @@ var (

func parseCommonPasswords() {
commonPasswords = make(map[string]struct{})
scanner := bufio.NewScanner(strings.NewReader(commonPasswordsRaw))
for scanner.Scan() {
p := strings.TrimSpace(scanner.Text())
if p == "" || strings.HasPrefix(p, "#") {
s := commonPasswordsRaw
for len(s) > 0 {
var line string
if i := strings.IndexByte(s, '\n'); i >= 0 {
line, s = s[:i], s[i+1:]
} else {
line, s = s, ""
}
p := strings.TrimSpace(line)
if p == "" || p[0] == '#' {
continue
}
commonPasswords[strings.ToLower(p)] = struct{}{}
Expand Down
Loading