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 @@ -15,3 +15,6 @@
## 2024-05-18 - Pre-compile Regex in SpellCheckerSession
**Learning:** `AndroidWordLevelSpellCheckerSession` previously instantiated new `Regex` objects for every quote matching and punctuation splitting operation during `onGetSuggestionsInternal`, which is a highly invoked method on the spellchecker hot-path.
**Action:** Always extract frequently instantiated `Regex` objects from hot paths (like text replacement or splitting) into `companion object` private constants (e.g. `periodRegex`, `quotesStartRegex`) to reduce allocation and regex compilation overhead per keystroke.
## 2024-05-18 - Pre-compile Regex in VoiceInputManager
**Learning:** `VoiceInputManager.syncRecognizedText` instantiates `Regex("[,.?!;:]")` inside a frequent method call, increasing allocation pressure on voice typing hot paths.
**Action:** Extract repeated `Regex` instantiations in input hot paths (such as `syncRecognizedText`) into companion object private constants to reduce memory allocation and compilation overhead.
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ class VoiceInputManager(

val isSmartPunctuationEnabled = ims.prefs().getBoolean(VoiceConstants.PREF_VOICE_SMART_PUNCTUATION, true)
val processedRaw = if (!isSmartPunctuationEnabled) {
rawText.replace(Regex("[,.?!;:]"), "")
rawText.replace(PUNCTUATION_REGEX, "")
} else {
rawText
}
Expand Down Expand Up @@ -1058,6 +1058,7 @@ class VoiceInputManager(

companion object {
private const val TAG = "VoiceInputManager"
private val PUNCTUATION_REGEX = Regex("[,.?!;:]")
private const val SAMPLE_RATE = 16000
private const val FRAME_SIZE_MS = 30
private const val FRAME_SIZE_SHORTS = SAMPLE_RATE * FRAME_SIZE_MS / 1000 // 480 shorts
Expand Down
Loading