[fpc-devel] Unnecessary string copy from Utf8String to AnsiString if destination CP is UTF8

Ondrej Pokorny lazarus at kluug.net
Mon Apr 29 00:05:37 CEST 2019

On 28.04.2019 23:28, Ondrej Pokorny wrote:
> But no problem, I'll change all method parameters that expect UTF8 
> strings from UTF8String to RawByteString and manually take care that 
> only UTF8 data is fed to them.

OK, I changed every single UTF8String to RawByteString and the 
performance gain was between 0% and 10%, depending on the test. So not 
really a big gain.

But when I run the same code in Delphi, it needs less than half the time 
of FPC (2 tests need 1/3 of FPC time, the third 1/2 of the time). I 
compared unmodified Release modes of Delphi and Lazarus.

The tests are all about parsing and creating UTF-8 text data. FPC 
doesn't need to do any conversions because I use FPC-native AnsiStrings 
with CP-UTF8, and Delphi needs to convert the input/output between 
UTF8/UTF16 (in Delphi I use the native UTF16 string type). Delphi is 
still much much faster.

I'll have to continue searching why the performance is so much better in 


More information about the fpc-devel mailing list