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 @@ -70,3 +70,6 @@
## 2026-06-13 - Replace regex replaceFirst with manual boundary strings check
**Learning:** The regex `,?\\b%s\\b,?` greedily removes both bounding commas if they exist, corrupting a list like \`a,b,c\` into \`ac\` when removing \`b\`. Replacing it with manual \`indexOf\`, boundary checks, and conditional index shifting not only fixes this data corruption bug but entirely bypasses regex compilation for a ~20x performance speedup on string manipulation.
**Action:** Always replace regex-based greedy delimiter removals with explicit character boundary logic.
## 2026-06-15 - Replace regex matches with manual index search for boundary checks
**Learning:** `String.matches(".*\\b%s\\b.*")` compiles the regex under the hood every time it is invoked, and the `.*` wildcards coupled with word boundaries (`\b`) can cause slow evaluation. Replacing this with an allocation-free manual `indexOf` loop combined with explicit boundary character checks (e.g., `,` or start/end of string) avoids regex compilation overhead and provides a significant ~40x performance speedup for delimited string membership checks.
**Action:** When checking if a specific token exists within a delimited string (like a comma-separated list), prefer manual `indexOf` loops with boundary checks over regex `matches` or `replaceAll` to avoid regex overhead and improve execution speed.
13 changes: 0 additions & 13 deletions BenchmarkOpt18.java

This file was deleted.

11 changes: 0 additions & 11 deletions BenchmarkOpt19.java

This file was deleted.

9 changes: 0 additions & 9 deletions BenchmarkOpt20.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,38 @@ public void should_remove_language_from_list()
// Remove non-existent
assertThat(ProjectPreferences.removeLanguage("java,cpp", "python")).isEqualTo("java,cpp");
}

@Test
public void should_check_language_in_list()
{
// ⚑ Bolt Performance Optimization Verification
// Test edge cases for replacing String.matches(".*\\b%s\\b.*")

// Match from middle
assertThat(ProjectPreferences.hasLanguage("java,python,cpp", "python")).isTrue();

// Match from start
assertThat(ProjectPreferences.hasLanguage("python,java", "python")).isTrue();

// Match from end
assertThat(ProjectPreferences.hasLanguage("java,python", "python")).isTrue();

// Match exact match
assertThat(ProjectPreferences.hasLanguage("python", "python")).isTrue();

// Reject when substring but not bounded (end)
assertThat(ProjectPreferences.hasLanguage("java,python3,cpp", "python")).isFalse();

// Reject when substring but not bounded (start)
assertThat(ProjectPreferences.hasLanguage("java,cpython,cpp", "python")).isFalse();

// Reject non-existent
assertThat(ProjectPreferences.hasLanguage("java,cpp", "python")).isFalse();

// Handle null/empty
assertThat(ProjectPreferences.hasLanguage("", "python")).isFalse();
assertThat(ProjectPreferences.hasLanguage(null, "python")).isFalse();
assertThat(ProjectPreferences.hasLanguage("python", null)).isFalse();
assertThat(ProjectPreferences.hasLanguage("python", "")).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,35 @@ public boolean hasPreferencesForLanguage(String language)
{
return store.getBoolean(BASE + LanguagePreferences.ANY_LANGUAGE + PROPERTIES_ACTIVE);
}
return orDefault(store.getString(LANGUAGES), "").matches(".*\\b%s\\b.*".formatted(language));
return hasLanguage(orDefault(store.getString(LANGUAGES), ""), language);
}

public static boolean hasLanguage(String languages, String language)
{
/*
* ⚑ Bolt Performance Optimization
*
* πŸ’‘ What: Replaced regex String.matches(".*\\b%s\\b.*") with manual string search and boundary checks.
* 🎯 Why: String.matches compiles a new regex Pattern every time, which is slow for frequent lookups.
* πŸ“Š Impact: ~40x speedup in microbenchmarks for this specific check.
* πŸ”¬ Measurement: Benchmarked against String.matches() in a loop.
*/
if (languages == null || languages.isEmpty() || language == null || language.isEmpty()) {
return false;
}
int idx = languages.indexOf(language);
while (idx != -1)
{
boolean startBoundary = (idx == 0 || languages.charAt(idx - 1) == ',');
boolean endBoundary = (idx + language.length() == languages.length() || languages.charAt(idx + language.length()) == ',');

if (startBoundary && endBoundary)
{
return true;
}
idx = languages.indexOf(language, idx + 1);
}
return false;
}

@Override
Expand Down
Loading