Performance issue in NextGen ARC model
Apart from being very slow during compilation, the Delphi NextGen compiler introduced a new memory model, named ARC.
We already spoke about ARC years ago, so please refer to our corresponding blog article for further information, especially about how Apple did introduce ARC to iOS instead of the Garbage Collector model.
About how ARC is to be used in the NextGen compiler, take a look at Marco's blog article, and its linked resources.
But the ARC model, as implemented by Embarcadero, has at least one huge
performance issue, in the way weak
references, and zeroing weak pointers have been implemented.
I do not speak about the general slow down introduced during every class/record initialization/finalization, which is noticeable, but not a big concern.
If you look at XE4 internals, you will discover a disappointing global lock introduced in the RTL.
The main issue is that XE4 RTL implements weak references with a global lock, which will slow down the whole process a lot, especially in multi-thread.
procedure TInstHashMap.RegisterWeakRef(Address: Pointer; Instance: Pointer); var H: Integer; Item: PInstItem; begin Lock; try H := Hash(Instance); Item := FindInstItem(Instance, H); if Item = nil then Item := AddInstItem(Instance, H); Item.RegisterWeakRef(Address); finally Unlock; end; end;
Lock/Unlock methods are implemented via
This synchronization class has the benefit to be cross-platform, but the drawback of being slower than other approaches.
Such a global lock will just kill the performance in multi-thread process.
Our weak pointer implementation for interfaces in uses a diverse approach, with a list per class type and small critical sections, so will be much more multi-thread friendly than XE4's implementation.
We can use ARC when targeting mobile platforms.
But in its current implementation, ARC would be a disaster about performance for a server application.
I'm waiting for XE5!
Please do not kill Delphi desktop/server application performance!
In October last year
we were already speaking about this global lock implementation issue, when
we discovered a pre-version of it in the XE3 RTL source code.
And the version shipped with XE4 did not improve anything.
How could EMB say that performance is a concern for them?
The more I see it, the more I think that enforcing strings to be immutable for performance reasons is just a joke, when you look at the current RTL state.