Use FillChar for debug fill patterns of 40 bytes and larger#96
Closed
janrysavy wants to merge 1 commit into
Closed
Use FillChar for debug fill patterns of 40 bytes and larger#96janrysavy wants to merge 1 commit into
janrysavy wants to merge 1 commit into
Conversation
janrysavy
marked this pull request as ready for review
July 21, 2026 09:44
Owner
|
Thanks Jan, I've implemented your suggestion. I have wrapped it in a "{$if CompilerVersion >= 28}" (XE7), because IIRC that is where FillChar saw a significant improvement. (Please let me know if I am wrong.) |
Author
|
Pierre, could you please reference the original PRs or issues in your commits so there’s a clear link back for future reference? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds a small
FillCharfast path toFillFreedDebugBlockWithDebugPatternandFillAllocatedDebugBlockWithDebugPatternfor user sizes of 40 bytes and larger. In the 4 KiB allocate/free benchmark, throughput improved by 52.36% to 62.89% on AMD and 104.58% to 128.59% on Intel across Win64 and Win32. Smaller blocks continue to use the original scalar code. For freed blocks, the code restores theTFastMM_FreedObjectpointer after filling, preserving the existing debug-block layout and diagnostics. The diff adds 15 lines.This is complementary to #92: that PR can disable fill patterns for profiling-oriented configurations, while this change speeds up the existing full diagnostic behavior when fill patterns remain enabled.
Tracking issue: #99
Benchmark
The benchmark repeatedly allocates and frees one block in FastMM5 debug mode with stack-trace collection disabled. Results are medians of 25 alternating baseline/candidate process pairs after three warmups. Throughput gain is
(baseline time / candidate time - 1) * 100; the 95% interval is a deterministic 10,000-resample bootstrap interval for the paired median.AMD Ryzen 9 7950X:
Intel Core i7-8750H:
The measured 4 KiB and 64 KiB cases improved substantially; the 64-byte controls were near the crossover, ranging from a 1.62% loss to a 10.55% gain. Additional 25-pair tests cover 1, 39, 40, and 41 bytes on both architectures.
The worst AMD result was -1.89% at one byte on Win32, with all Win64 controls positive. On Intel, the worst results were -1.62% at 39 bytes on Win32 (CI -2.37% to -0.08%) and -1.27% at 39 bytes on Win64 (CI -2.26% to -0.33%). Avoiding those small boundary losses would require duplicating or restructuring the scalar loops, which does not seem justified for debug mode.
Tests ran on an AMD Ryzen 9 7950X and an Intel Core i7-8750H under Windows 11 build 26200, using Delphi Win32/Win64 37.0.59082.6021 with release-style
-O+builds. The Intel runs use fewer operations to keep process duration similar; both builds still perform identical work within each pair, and the pairing and analysis are unchanged.Correctness
FastMMDebugPatternTest.dprpasses for the DCC 37 baseline and candidate on Win32 and Win64 on both CPUs. Additional compatibility runs pass with DCC 35 and 36 Win32/Win64 and with DCC 37PurePascal. The test verifies every allocated fill byte for sizes 1 through 1025, then corrupts and restores every byte for freed-block sizes 1 through 65 and 257. It accepts only the expectedEInvalidPointerand requires a clean scan afterward, covering the object marker and every baseline 8/4/2/1-byte remainder path.Full benchmark source, raw AMD and Intel samples, summaries, and correctness tests: https://github.com/janrysavy/FastMM5/tree/ed3229e678bbe4b2455b8435168442d51f430996/perf-review
Compatibility note
FastMM5 supports Delphi versions older than the DCC 35 through 37 compilers used here.
FillCharis suitable for this code and does not allocate. The original scalar path remains below 40 bytes, but the crossover should still be checked with the oldest supported RTL.