Skip to content

Fix slow UTF-16 string reads#18

Open
dummycount wants to merge 1 commit intoShadowth117:masterfrom
dummycount:text-read-perf
Open

Fix slow UTF-16 string reads#18
dummycount wants to merge 1 commit intoShadowth117:masterfrom
dummycount:text-read-perf

Conversation

@dummycount
Copy link
Copy Markdown
Contributor

ReferenceGenerator.ReadCMXText() was taking longer than expected, and Visual Studio's profiler was showing the "new char[blockSize / 2]" line of ReadUTF16String() to be taking the majority of the time. This was caused by PSO2Text asking to read the entire remaining data in the file every time it needed to read a string. Letting it use the default read size and just keep doing more reads if it didn't find the end of the string is significantly faster.

Also improved ReadUTF16String() to replace an intermediate string allocation with a span.

Together, these reduce ReferenceGenerator.ReadCMXText() from 8-10 seconds to about 0.7 seconds on my machine.

ReferenceGenerator.ReadCMXText() was taking longer than expected, and
Visual Studio's profiler was showing the "new char[blockSize / 2]" line
of ReadUTF16String() to be taking the majority of the time. This was
caused by PSO2Text asking to read the entire remaining data in the file
every time it needed to read a string. Letting it use the default read
size and just keep doing more reads if it didn't find the end of the
string is significantly faster.

Also improved ReadUTF16String() to replace an intermediate string
allocation with a span.

Together, these reduce ReferenceGenerator.ReadCMXText() from 8-10
seconds to about 0.7 seconds on my machine.
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