Whilst benchmarking a real-world application I came across a surprising performance characteristic relating to the zlib and zip libraries that ship with Delphi.
My
As noted, the Delphi ZIP compression code stands on top of zlib. The Delphi implementation of zlib is a wrapper around the official zlib C source code. The C code is compiled to objects and then linked with {$LINK}
. For XE7, the comments at the top of System.ZLib
indicate that zlib 1.2.8 was used.
Under the obvious assumption that the time is being spent inside the zlib code, the most plausible explanation for the behaviour is that the 64 bit compiled objects are responsible for the poor performance. Either the compiler used is emitting weak code, or a poor choice of compiler options has been used.
So, I took the following steps:
/O2 /GS-
. System.ZLib.pas
and included it in my project, alongside the newly compiled objects. This ensures that the newly compiled zlib objects are used.The run time, on the same machine as used to generate the data in the question was 6,912ms.
I then recompiled and omitted the /O2
option and went round the loop again. This time the run time was 20,077ms. So I hypothesise that Embarcadero have just been forgetting to compile these objects with optimisations.
I have reported this issue to Embarcadero's Quality Portal: https://quality.embarcadero.com/browse/RSP-9891
As mentioned in a comment below, it seems quite plausible that other libraries that rely on compiled objects may have similar problems. Potential problem areas include:
Update
The Quality Portal issue reports that this issue was fixed in XE8.