#1 2026-07-09 18:30:06

RObyDP
Member
Registered: 2015-02-19
Posts: 66

delphi13.1 with windows heap

Hi,

I tested the latest mORMot benchmark with Delphi 13.1 (64-bit). Everything works fine except for one function.

When using the Windows heap manager directly (for example, https://github.com/RDP1974/DelphiMSHeap), the following test:

`procedure TTestCoreBase.Utf8Slow(Context: TObject);`

raises memory-related exceptions, such as:

`UTF-8TDynArray: #2421041 EAccessViolation`

Feel free to check the code and let me know if you find anything relevant.

Thank you.
R.

just for talk, win2025 server desktop requires 1m40secs, same vm win 2025 core requires 1m05secs

Last edited by RObyDP (2026-07-09 20:12:52)

Offline

#2 2026-07-10 09:43:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,554
Website

Re: delphi13.1 with windows heap

Neither the Delphi MM, nor the FPC MM, nor both in debug/extended mode do trigger such error.
It is very likely that something is missing in your DelphiMSHeap logic, like handling of a nil pointer or a size <= 0.

Offline

#3 2026-07-10 11:07:10

RObyDP
Member
Registered: 2015-02-19
Posts: 66

Re: delphi13.1 with windows heap

Sorry to bother you.

I checked all integer values for zero or negative numbers, as well as all pointers for "nil", but nothing was reported.

In Debug mode everything works fine. In Release mode the issue is intermittent: sometimes no error is reported, but quite often this function raises an "EAccessViolation".

best regards

Offline

#4 2026-07-10 13:45:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,554
Website

Re: delphi13.1 with windows heap

In my custom RTL for Delphi 7 I used something like this for the Win heap usage:
https://gist.github.com/synopse/d7f6307 … 62b317c93c

Anyway, we need more info about how it happens.

Offline

#5 2026-07-10 21:20:33

RObyDP
Member
Registered: 2015-02-19
Posts: 66

Re: delphi13.1 with windows heap

Hi,
I hope this helps.

With tbbmalloc (https://github.com/RDP1974/Delphi64RTL) (both 32-bit and 64-bit), all tests pass 100%.

Using Microsoft Heap API (https://github.com/RDP1974/DelphiMSHeap), the 32-bit version also passes 100% of the tests. However, the 64-bit version consistently fails in one function with an EAccessViolation in UTF8 TDynArray.

Best regards.
R.

btw. win64 1m05s, win32 1m45s (tbbmalloc)

Last edited by RObyDP (2026-07-10 21:27:16)

Offline

#6 2026-07-11 05:38:22

Chaa
Member
Registered: 2011-03-26
Posts: 264

Re: delphi13.1 with windows heap

Line that fails:
https://github.com/synopse/mORMot2/blob … .pas#L6906
i.e. if I comment this line, all tests are passed.

I think that on invalid UTF-8 sequence function StrPosIReference may read past of string, at line:
https://github.com/synopse/mORMot2/blob … pas#L12324
and can raise EAccessViolation.

Error message from console:
EAccessViolation for 29[<8L$c3$a3$c3$8f4QJX+7awvq/Z$c3$abco~S<V$c3$af]25

Offline

#7 2026-07-11 12:08:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,554
Website

Re: delphi13.1 with windows heap

Please try with
https://github.com/synopse/mORMot2/commit/ebf12e975
Such invalid UTF-8 sequence should be detected now.

But the test code should not generate invalid UTF-8. And in fact, the value displayed seems fine.
Perhaps the test code itself is wrong. wink

Edit:The test code did generate invalid UTF-8 on purpose via SetLength(Up2, length(Up2) - 1);
So the code was not strong enough.

Offline

#8 2026-07-12 11:51:42

RObyDP
Member
Registered: 2015-02-19
Posts: 66

Re: delphi13.1 with windows heap

with msheap now works perfect 100%
thank you
btw. 1m00s time on win11 25h2 intel i9900kf

Last edited by RObyDP (2026-07-12 11:54:51)

Offline

#9 2026-07-12 14:21:01

esmondb
Member
From: London
Registered: 2010-07-20
Posts: 301

Re: delphi13.1 with windows heap

btw I was told as a child that if a computer took more than a 1/5 of a second to respond it would seem stupid to a human

Offline

#10 2026-07-12 20:21:39

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,554
Website

Re: delphi13.1 with windows heap

I have made a full review pass on UTF-8 decode hardening, in the whole unit.
Code should be much stronger now. Perhaps a little slower.

@R0byDP
I don't understand why you only benchmark on Windows.
For performance, Linux is far ahead. I run the regression tests natively as 16 secs on my Debian 13 with Intel Core I5 13500.

Offline

Board footer

Powered by FluxBB