Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@
## 2024-05-18 - Optimize Diacritic Stripping in Suggest
**Learning:** In `Suggest.isSameIgnoringAccents`, `val DIACRITIC_REGEX = "\\p{M}+".toRegex()` was being used in combination with `Normalizer.normalize` and `replace` to strip accents. This created string allocations via `Normalizer.normalize` and `Regex.replace` even for plain ASCII strings that lack accents, which is a hot path during typing and suggestion processing.
**Action:** Replace `Regex.replace` with a manual character loop that avoids `Normalizer.normalize` entirely for pure ASCII strings and strips `Character.NON_SPACING_MARK` without regex allocation when normalizing.
## 2024-05-18 - Optimize Regex pattern detection in DictionaryFacilitatorImpl
**Learning:** `DictionaryFacilitatorImpl.isRegexPattern` used chained `String.contains()` and `String.startsWith()` calls, which internally execute full loops over the string (or delegate to regex). Replacing these chained calls with a single manual O(N) iteration reduces overhead and prevents repeatedly traversing the string.
**Action:** Replace chained string detection methods (`contains`, `startsWith`, `endsWith`) with a single manual loop over the string's indices when checking multiple characters in performance hot paths.
Original file line number Diff line number Diff line change
Expand Up @@ -1235,15 +1235,22 @@ private class DictionaryGroup(
private var compiledBlacklistPatterns: List<Regex> = emptyList()

private fun isRegexPattern(pattern: String): Boolean {
return pattern.contains(".*")
|| pattern.contains(".+")
|| pattern.startsWith("^")
|| pattern.endsWith("$")
|| pattern.contains("[")
|| pattern.contains("(")
|| pattern.contains("\\")
|| pattern.contains("|")
|| pattern.contains("{")
if (pattern.isEmpty()) return false
val len = pattern.length

// ⚑ Bolt: Optimize regex pattern detection
// Replaced chained String.contains() and startsWith() calls with a single
// manual character iteration loop to reduce method overhead and execution time.
if (pattern[0] == '^' || pattern[len - 1] == '$') return true
for (i in 0 until len) {
val c = pattern[i]
if (c == '[' || c == '(' || c == '\\' || c == '|' || c == '{') return true
if (c == '.' && i + 1 < len) {
val next = pattern[i + 1]
if (next == '*' || next == '+') return true
}
}
return false
}

private fun rebuildCompiledPatterns() {
Expand Down
Loading