From eec2895c815b33955b608b50e243cd2877c6aa3a Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Mon, 3 Aug 2026 12:13:45 +0100 Subject: [PATCH] perf(Core): Avoid boxing tuple comparisons The existing tuple comparison code 1) Allocates large numbers of reference tuples 2) Uses boxing comparisons which allocate large numbers of integers Explicitly using struct tuples and CompareTo avoids all of these allocations. Benchmarks before, using the extended set of selfcheck rules | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------- |--------:|---------:|---------:|-----------:|-----------:|----------:|----------:| | LintParsedFile | 1.402 s | 0.0123 s | 0.0109 s | 31000.0000 | 10000.0000 | 2000.0000 | 518.02 MB | After | Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated | |--------------- |--------:|---------:|---------:|-----------:|----------:|----------:|----------:| | LintParsedFile | 1.282 s | 0.0041 s | 0.0032 s | 15000.0000 | 6000.0000 | 2000.0000 | 263.96 MB | --- src/FSharpLint.Core/Framework/Utilities.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FSharpLint.Core/Framework/Utilities.fs b/src/FSharpLint.Core/Framework/Utilities.fs index e9fcf5a9d..266342a49 100644 --- a/src/FSharpLint.Core/Framework/Utilities.fs +++ b/src/FSharpLint.Core/Framework/Utilities.fs @@ -158,8 +158,8 @@ module ExpressionUtilities = |> Option.defaultValue 0 let rangeContainsOtherRange (containingRange:Range) (range:Range) = - (range.StartLine, range.StartColumn) >= (containingRange.StartLine, containingRange.StartColumn) - && (range.EndLine, range.EndColumn) <= (containingRange.EndLine, containingRange.EndColumn) + (struct (range.StartLine, range.StartColumn)).CompareTo(struct(containingRange.StartLine, containingRange.StartColumn)) > -1 + && (struct (range.EndLine, range.EndColumn)).CompareTo(struct(containingRange.EndLine, containingRange.EndColumn)) < 1 /// Active pattern to match any SynExpr.LetOrUse /// Returns a tuple of (record, isBang, isUse) allowing matching on both booleans and accessing the full record