This PR improves the performance of the SVG parser.
It is very large PR that I've started almost 3 months ago.
Optimizations:
Fixing the leaking {$OVERFLOWCHECKS ON} in Img32.SVG.Core.pas improves the speed of the code that comes below the leaks.
All New(PSvgAttrib(attrib)) are replaced by an inlined helper function, that doesn't rely on the slow RTTI. Also the Dispose(PSvgAttrib(attrib)) is replaced by a helper function that skips the RTTI code and clears the two UTF8String itself.
A lot of element in Set operators are replaced by case element of that Delphi's Win64 compiler can optimize whereas it lacks the ability to optimize the in-operator.
Many string parsing functions don't use a var-parameter for the PUTF8Char anymore because that forced the iterator variable to be stored and loaded from memory every time the code accesses it. Especially loops were affected by this.
Code that resized dynamic arrays now calculates the final number of elements before calling SetLength
Numbers in SVG files are parsed with multiple data type stages: Integer->Int64->Double. So "smaller" numbers can be parsed much faster.
TColorConstList and TClassStylesList are now HashMaps with UTF8Strings instead of UnicodeStrings that had to be cast forth and back.
GetHash got an overload that accepts a PUTF8Char and a len-parameter. If ToUTF8String was only used to call GetHash, then we can now skip the UTF8String creation and call GetHash directly on the input PUTF8Char.
GetBoundsD is now CPU register optimized for 32bit and for 64bit
By using TList.List[] instead of TList.Items[] the code now skips the Lists's index check in for-loop that iterate over the whole list.
This PR also fixes the Delphi 2007 compilation. Delphi 2007 seems to have an function overload resolver bug. It tries to call Math.Min(Extended, Extended) for two NativeInt parameters.
This PR improves the performance of the SVG parser. It is very large PR that I've started almost 3 months ago.
Optimizations:
{$OVERFLOWCHECKS ON}
in Img32.SVG.Core.pas improves the speed of the code that comes below the leaks.New(PSvgAttrib(attrib))
are replaced by an inlined helper function, that doesn't rely on the slow RTTI. Also theDispose(PSvgAttrib(attrib))
is replaced by a helper function that skips the RTTI code and clears the two UTF8String itself.element in Set
operators are replaced bycase element of
that Delphi's Win64 compiler can optimize whereas it lacks the ability to optimize the in-operator.SetLength
TColorConstList
andTClassStylesList
are now HashMaps with UTF8Strings instead of UnicodeStrings that had to be cast forth and back.GetHash
got an overload that accepts a PUTF8Char and a len-parameter. IfToUTF8String
was only used to callGetHash
, then we can now skip the UTF8String creation and callGetHash
directly on the input PUTF8Char.GetBoundsD
is now CPU register optimized for 32bit and for 64bitTList.List[]
instead ofTList.Items[]
the code now skips the Lists's index check in for-loop that iterate over the whole list.This PR also fixes the Delphi 2007 compilation. Delphi 2007 seems to have an function overload resolver bug. It tries to call
Math.Min(Extended, Extended)
for twoNativeInt
parameters.