Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

hspragg-godaddy
Copy link

@hspragg-godaddy hspragg-godaddy commented Oct 17, 2025

Background

While developing some test container tests, using 60 separate SQL files, I noticed my TestContainers were taking upwards of 6 minutes to load. Each script file has a single, relatively small (under 100 lines), create/alter/insert statement.

After running a profiler I noticed that the culprit for the load time was this ScriptSplitter method.
image

Problem

Specifically the StringBuilder.toString method being called to check if the last character is whitespace or not results in the entire StringBuilder array to be re-built every time it encounters whitespace in the ScriptScanner.

Based on my, very surface-level, analysis, it seems the result is O(n*m) performance where n is the content of a SQL file and m is the number of Lexem objects discovered by the ScriptScanner.

Proposed Solution

By instead utilizing StringBuilder's charAt method, it should ensure this check is always O(1) by doing a direct byte array lookup to see if the last character is a space character.

image

Also, using StringBuilder.length() == 0 over StringBuilder.isEmpty for backwards compatibility sake.

Fixed an issue with the `ScriptSplitter#split` method, where encountering whitespace would result in the StringBuilder building the entire string just to check the last character in the string.
@hspragg-godaddy hspragg-godaddy requested a review from a team as a code owner October 17, 2025 22:01
Changed the logic from `isNotEmpty and doesNotEndInSpace` to `isEmpty or doesNotEndInSpace` to align with previous implementation behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.