canontra-0.4.0.0: bench/Bench.hs
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Main
Description : Empirical research benchmark suite for Canontra v0.4.0 (RQ1-RQ19).
This suite empirically evaluates canontra v0.4.0 across 19 Research Questions (RQs),
from Core Pipeline Stages, Polyglot ByteString/SIMD Parsers, SwissTable Interning,
Fused Streaming, Unboxed CSR Graphs, CNTR\x06 & CNTR\x07 Slab Caches, Bound
Alpha-Canonicalization & CFG RPO, Algebraic Equivalence, to Stateless AI Harness
Semantic Sub-Versioning (@canontra snap@).
-}
module Main (main) where
import qualified Data.Aeson as Aeson
import qualified Data.ByteString as BS
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy as LBS
import Data.List (foldl')
import qualified Data.Map.Strict as Map
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import GHC.IO.Encoding (setFileSystemEncoding, setForeignEncoding, setLocaleEncoding, utf8)
import System.IO (hSetEncoding, stderr, stdout)
import Test.Tasty.Bench
import Canontra.Analysis.CallGraph (buildCallGraph)
import Canontra.Analysis.CFG (buildCFGs)
import Canontra.Analysis.CompactGraph (fromControlFlowGraph, fromDataFlowGraph)
import Canontra.Analysis.DFG (buildDFGs)
import Canontra.Analysis.Scope (analyzeProgramScope)
import Canontra.Cache.Inode (FileMetadata (..))
import Canontra.Cache.MerkleCache (MerkleCache (..), decodeBinaryCache, emptyCache, encodeBinaryCache, insertCache, lookupBinaryCache, lookupCache)
import Canontra.Canonical.FastScan (fastCanonicalizeBS, scanAsciiAndLineEndings)
import Canontra.Canonical.FusedStream (fusedHashDeclarations, fusedHashProgram)
import Canontra.Canonical.Serialize (canonicalizeProgram)
import Canontra.Canonical.StreamingHash (hashBuilderDirect)
import Canontra.Canonical.Unicode (canonicalizeText)
import Canontra.Fingerprint.Bundle (computeBundle, computeBundleFromSource)
import Canontra.Fingerprint.CallGraph (computeFCG)
import Canontra.Fingerprint.Composite (computeF4)
import Canontra.Fingerprint.ControlFlow (computeFCF)
import Canontra.Fingerprint.DataFlow (computeFDF)
import Canontra.Fingerprint.Declaration (computeF2, extractDeclarations)
import Canontra.Fingerprint.Dependency (computeF3)
import Canontra.Fingerprint.Source (computeF0, hashBytes)
import Canontra.Fingerprint.Structural (computeF1)
import Canontra.IR.Arena (fusedHashLinearAST, programToLinearAST)
import Canontra.Normalize.Fused (fusedNormalizeProgram)
import Canontra.Normalize.Normalize (normalizeProgram)
import Canontra.Parser.FastPython (parseFastPythonByteString, parseFastPythonSource, parseFastPythonToArena)
import Canontra.Parser.Go (parseGoByteString, parseGoSource)
import Canontra.Parser.Ingest (ingestOutlineSource, ingestSource)
import Canontra.Parser.JS (parseJSByteString, parseJSSource)
import Canontra.Parser.Outline (computeF2Outline, computeF3Outline, parseOutlineGo, parseOutlineJS, parseOutlinePython, parseOutlineRust)
import Canontra.Parser.Polyglot (parsePolyglotByteString)
import Canontra.Parser.Python (parsePythonSource)
import Canontra.Parser.Rust (parseRustByteString, parseRustSource)
import Canontra.Parser.SwissTable (emptySwissTable, swissInternBS, swissLookupBS, swissResolveId)
import Canontra.Parser.SymbolTable (SymbolId (..), emptySymbolTable, internManyBS, internSymbolBS, preloadPolyglotKeywords, resolveSymbolBS)
import Canontra.Repository.MerkleDAG (buildMerkleDAG, diffMerkleDAG, merkleDAGRootHash)
import Canontra.Analysis.CSRGraph (buildCSRGraph, condenseSCC, csrHasEdge, forwardReachabilityCone, spliceCSREdges, tarjanSCC, transposeCSR)
import Canontra.Analysis.BatchImpact (computeBatchImpactSliceCSR)
import Canontra.Analysis.CFGCanonical (canonicalizeCFGRPO)
import Canontra.Analysis.Impact (classifySeverity, computeImpactSlice, computeImpactSliceCSR)
import Canontra.Analysis.TypeContract (extractTypeContracts)
import Canontra.Normalize.Algebraic (normalizeAlgebraicProgram)
import Canontra.Normalize.Alpha (canonicalizeAlphaProgram)
import Canontra.Analysis.WholeRepoGraph
( buildCSRCallGraph
, buildCSRDataFlow
, buildWholeRepoCallGraph
, buildWholeRepoCallGraphFromSummaries
, buildWholeRepoDataFlow
, buildWholeRepoDataFlowFromSummaries
, extractFileGraphSummary
, incrementalUpdateWholeRepoGraphs
, toCSRCallGraph
)
import Canontra.Cache.PagedCache (decodeBinaryCacheV5, encodeBinaryCacheV5, lookupBinaryCacheV5)
import Canontra.Cache.SlabV6 (decodeCSRGraph, decodeSlabV6Binary, encodeCSRGraph, encodeSlabV6Binary, lookupSlabBinaryBS)
import Canontra.Cache.SlabV7 (SlabV7Entry (..), decodeSlabV7Binary, encodeSlabV7Binary, lookupSlabV7BinaryBS)
import Canontra.Canonical.SIMDScan (fastCanonicalizeSIMD, isPureAsciiUnixSIMD, scanSourceSIMD)
import Canontra.Fingerprint.TypeContract (computeFT)
import Canontra.Fingerprint.WholeRepoCallGraph (computeFWCG)
import Canontra.Fingerprint.WholeRepoDataFlow (computeFWDF)
import Canontra.Harness.Guard (matchesGlob, parseGuardTiers)
import Canontra.Harness.Store (SnapFileRecord (..))
import Canontra.Harness.SubVersion (classifySnapDeltas, computeFileDeltas, diffFileBundles)
import Canontra.IR.Expression (Op (..))
import Canontra.Repository.Parallel (newChaseLevDeque, parMapChunks, parProcessWorkStealing, popBottom, pushBottom, stealBatchTop)
import Canontra.Repository.Repository (computeRepositoryFingerprint)
import Canontra.Types (FileEntry (..), Fingerprint (..), FingerprintBundle (..))
import Canontra.Verification.Metamorphic (MetamorphicMutation (..), MetamorphicTransform (..), runMetamorphicSuite, verifyMetamorphicProgramTransform, verifyProgramMutation)
-- | Generates synthetic Python module with n function definitions
generateSyntheticPython :: Int -> T.Text
generateSyntheticPython n =
T.unlines $
[ "import math"
, "import os"
, "from collections import defaultdict"
, ""
] ++ concatMap (\i ->
[ "def compute_metric_" <> T.pack (show i) <> "(alpha: float, beta: float = 1.0, verbose: bool = False) -> float:"
, " \"\"\"Docstring for function " <> T.pack (show i) <> " to test stripping.\"\"\""
, " scale = alpha * " <> T.pack (show (i + 1))
, " accumulator = 0.0"
, " if scale > 50.0:"
, " accumulator += (scale * 2.5) + beta"
, " else:"
, " accumulator -= (scale * 0.5) - beta"
, " return accumulator"
, ""
]) [1 .. n]
-- | Generates synthetic TypeScript module with n function definitions
generateSyntheticTS :: Int -> T.Text
generateSyntheticTS n =
T.unlines $
[ "import { calculate } from './calc';"
, ""
] ++ concatMap (\i ->
[ "export function computeMetric" <> T.pack (show i) <> "(alpha: number, beta: number = 1.0): number {"
, " const scale = alpha * " <> T.pack (show (i + 1)) <> ";"
, " return scale + beta;"
, "}"
, ""
]) [1 .. n]
-- | Generates synthetic Go module with n function definitions
generateSyntheticGo :: Int -> T.Text
generateSyntheticGo n =
T.unlines $
[ "package mathops"
, "import \"fmt\""
, ""
] ++ concatMap (\i ->
[ "func ComputeMetric" <> T.pack (show i) <> "(alpha float64, beta float64) float64 {"
, " scale := alpha * " <> T.pack (show (i + 1))
, " return scale + beta"
, "}"
, ""
]) [1 .. n]
-- | Generates synthetic Rust module with n function definitions
generateSyntheticRust :: Int -> T.Text
generateSyntheticRust n =
T.unlines $
[ "use std::collections::HashMap;"
, ""
] ++ concatMap (\i ->
[ "pub fn compute_metric_" <> T.pack (show i) <> "(alpha: f64, beta: f64) -> f64 {"
, " let scale = alpha * " <> T.pack (show (i + 1)) <> ".0;"
, " scale + beta"
, "}"
, ""
]) [1 .. n]
main :: IO ()
main = do
setLocaleEncoding utf8
setForeignEncoding utf8
setFileSystemEncoding utf8
hSetEncoding stdout utf8
hSetEncoding stderr utf8
-- Pre-generate benchmark inputs of multiple scales
let microSrc = generateSyntheticPython 2 -- ~25 LOC
smallSrc = generateSyntheticPython 10 -- ~85 LOC
medSrc = generateSyntheticPython 50 -- ~405 LOC
largeSrc = generateSyntheticPython 200 -- ~1,605 LOC
xlSrc = generateSyntheticPython 500 -- ~4,005 LOC
microBytes = TE.encodeUtf8 microSrc
smallBytes = TE.encodeUtf8 smallSrc
medBytes = TE.encodeUtf8 medSrc
largeBytes = TE.encodeUtf8 largeSrc
xlBytes = TE.encodeUtf8 xlSrc
tsSmall = generateSyntheticTS 10 -- ~85 LOC
tsMed = generateSyntheticTS 50 -- ~405 LOC
tsLarge = generateSyntheticTS 200 -- ~1,605 LOC
tsSmallBytes = TE.encodeUtf8 tsSmall
goSmall = generateSyntheticGo 10 -- ~85 LOC
goMed = generateSyntheticGo 50 -- ~405 LOC
goLarge = generateSyntheticGo 200 -- ~1,605 LOC
goSmallBytes = TE.encodeUtf8 goSmall
rsSmall = generateSyntheticRust 10 -- ~85 LOC
rsMed = generateSyntheticRust 50 -- ~405 LOC
rsLarge = generateSyntheticRust 200 -- ~1,605 LOC
rsSmallBytes = TE.encodeUtf8 rsSmall
-- Mutation Fixtures
baseCode = T.unlines
[ "def calculate(x: int, y: int = 10) -> int:"
, " \"\"\"Docstring to strip.\"\"\""
, " result = x + y"
, " return result"
]
mutWhitespace = T.unlines
[ "def calculate( x : int , y : int = 10 ) -> int :"
, ""
, " \"\"\"Docstring to strip.\"\"\""
, " result = x + y"
, " return result"
]
mutComments = T.unlines
[ "# Leading comment"
, "def calculate(x: int, y: int = 10) -> int:"
, " # Inner comment"
, " \"\"\"Docstring to strip.\"\"\""
, " result = x + y # trailing comment"
, " return result"
]
mutBody = T.unlines
[ "def calculate(x: int, y: int = 10) -> int:"
, " \"\"\"Docstring to strip.\"\"\""
, " result = (x * 2) + y"
, " return result"
]
-- 1000 sample identifier ByteStrings for SymbolTable benchmark
sampleIdentifiers = [ "var_identifier_" <> BS.pack (map (fromIntegral . fromEnum) (show (i :: Int))) | i <- [1..1000] ]
(!_, !benchSymTable) = internManyBS sampleIdentifiers emptySymbolTable
case ( parsePythonSource "micro.py" microSrc
, parsePythonSource "small.py" smallSrc
, parsePythonSource "med.py" medSrc
, parsePythonSource "large.py" largeSrc
, parsePythonSource "xl.py" xlSrc
) of
(Right microProg, Right smallProg, Right medProg, Right largeProg, Right xlProg) -> do
-- Mock repository entries for RQ4
let makeRepoEntries :: Int -> [FileEntry]
makeRepoEntries n =
[ FileEntry ("src/module_" ++ show i ++ ".py")
(FingerprintBundle
(Fingerprint $ T.pack $ "s" ++ show i)
(Fingerprint $ T.pack $ "str" ++ show i)
(Fingerprint $ T.pack $ "d" ++ show i)
(Fingerprint $ T.pack $ "dp" ++ show i)
(Fingerprint $ T.pack $ "cg" ++ show i)
(Fingerprint $ T.pack $ "cf" ++ show i)
(Fingerprint $ T.pack $ "df" ++ show i)
(Fingerprint $ T.pack $ "t" ++ show i)
(Fingerprint $ T.pack $ "c" ++ show i))
| i <- [1 .. n]
]
repo10 = makeRepoEntries 10
repo50 = makeRepoEntries 50
repo200 = makeRepoEntries 200
repo500 = makeRepoEntries 500
repo1000 = makeRepoEntries 1000
sampleMeta = FileMetadata "src/module_1.py" 1024 1700000000
sampleBundle = head repo10
populatedCache = insertCache "src/module_1.py" sampleMeta (feFingerprints sampleBundle) emptyCache
largeCache = foldl' (\c (FileEntry p b) -> insertCache p (FileMetadata p 1024 1700000000) b c) emptyCache repo1000
largeCacheBin = encodeBinaryCache largeCache
largeCacheJSON = LBS.toStrict (Aeson.encode largeCache)
repoEntries1000 = [(p, b) | FileEntry p b <- repo1000]
dag1000 = buildMerkleDAG repoEntries1000
dummyBundleM = FingerprintBundle (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m") (Fingerprint "m")
dag1000Mod = buildMerkleDAG (("src/module_500.py", dummyBundleM) : tail repoEntries1000)
benchSwissTable = snd $ foldl' (\(_, tbl) bs -> swissInternBS tbl bs) (SymbolId 0, emptySwissTable 1024) sampleIdentifiers
xlArena = programToLinearAST xlProg
largeCacheV5Bin = encodeBinaryCacheV5 largeCache
modules10 = [("src/module_" ++ show i ++ ".py", if i == 1 then microProg else smallProg) | i <- [1..10 :: Int]]
wcg10 = buildWholeRepoCallGraph modules10
polyglotFixtures = [("small.py", smallSrc), ("small.ts", tsSmall), ("small.go", goSmall)]
-- v0.2.0 Benchmark Fixtures
csrEdges500 = [ (fromIntegral (i `mod` 100), fromIntegral ((i * 3 + 7) `mod` 100), 1) | i <- [1..500 :: Int] ]
csrGraph100 = buildCSRGraph 100 csrEdges500
slabEntries1000 = [ (fePath e, FileMetadata (fePath e) 1024 1700000000, feFingerprints e) | e <- repo1000 ]
slabV6Bin = encodeSlabV6Binary slabEntries1000 Nothing
summaries10 = [extractFileGraphSummary p pr | (p, pr) <- modules10]
slabV7Entries10 =
[ SlabV7Entry (FileMetadata p 1024 1700000000) (feFingerprints (head repo10)) (Just s)
| ((p, _), s) <- zip modules10 summaries10
]
slabV7Bin10 = encodeSlabV7Binary slabV7Entries10 Nothing
(wcg10Graph, _) = buildCSRCallGraph modules10
(wdf10Graph, _) = buildCSRDataFlow modules10
csrPair10 = toCSRCallGraph wcg10Graph
csrEncodedBS = LBS.toStrict (BB.toLazyByteString (encodeCSRGraph csrGraph100))
snapMap1000 = Map.fromList
[ (fePath e, SnapFileRecord (fePath e) (unFingerprint (f0Source (feFingerprints e))) 1024 (feFingerprints e))
| e <- repo1000
]
snapMap1000Mod = Map.insert "src/module_500.py"
(SnapFileRecord "src/module_500.py" "modified_f0" 1024 dummyBundleM)
snapMap1000
snapDirtyDeltas = computeFileDeltas snapMap1000 snapMap1000Mod
defaultMain
[ bgroup "RQ1: Pipeline Latency across Scales"
[ bgroup "1. AST Parsing"
[ bench "Micro (~25 LOC)" $ nf (parsePythonSource "micro.py") microSrc
, bench "Small (~85 LOC)" $ nf (parsePythonSource "small.py") smallSrc
, bench "Medium (~405 LOC)" $ nf (parsePythonSource "med.py") medSrc
, bench "Large (~1605 LOC)" $ nf (parsePythonSource "large.py") largeSrc
, bench "XL (~4005 LOC)" $ nf (parsePythonSource "xl.py") xlSrc
]
, bgroup "2. AST Normalization & Serialization"
[ bench "Micro (~25 LOC)" $ nf (canonicalizeProgram . normalizeProgram) microProg
, bench "Small (~85 LOC)" $ nf (canonicalizeProgram . normalizeProgram) smallProg
, bench "Medium (~405 LOC)" $ nf (canonicalizeProgram . normalizeProgram) medProg
, bench "Large (~1605 LOC)" $ nf (canonicalizeProgram . normalizeProgram) largeProg
, bench "XL (~4005 LOC)" $ nf (canonicalizeProgram . normalizeProgram) xlProg
]
, bgroup "3. Semantic Graph Analysis"
[ bench "Scope Analysis (XL)" $ nf analyzeProgramScope xlProg
, bench "Call Graph Extraction (XL)" $ nf buildCallGraph xlProg
, bench "Control-Flow Graph (CFG) (XL)"$ nf buildCFGs xlProg
, bench "Data-Flow Graph (DFG) (XL)" $ nf buildDFGs xlProg
]
, bgroup "4. Cryptographic Hashing"
[ bench "F0 Raw Bytes Hash (XL)" $ nf computeF0 xlBytes
, bench "F1 Structural Hash (XL)" $ nf computeF1 xlProg
, bench "F2 Declaration Hash (XL)" $ nf computeF2 xlProg
, bench "F3 Dependency Hash (XL)" $ nf computeF3 xlProg
, bench "F_CG Call Graph Hash (XL)" $ nf computeFCG xlProg
, bench "F_CF Control-Flow Hash (XL)"$ nf computeFCF xlProg
, bench "F_DF Data-Flow Hash (XL)" $ nf computeFDF xlProg
, bench "F4 Composite Hash" $ nf (\fp -> computeF4 fp fp fp fp fp fp fp) (Fingerprint "test")
]
, bgroup "5. Full 8-Tier Pipeline"
[ bench "Micro (~25 LOC)" $ nf (\s -> computeBundle "micro.py" microBytes s) microSrc
, bench "Small (~85 LOC)" $ nf (\s -> computeBundle "small.py" smallBytes s) smallSrc
, bench "Medium (~405 LOC)" $ nf (\s -> computeBundle "med.py" medBytes s) medSrc
, bench "Large (~1605 LOC)" $ nf (\s -> computeBundle "large.py" largeBytes s) largeSrc
, bench "XL (~4005 LOC)" $ nf (\s -> computeBundle "xl.py" xlBytes s) xlSrc
]
]
, bgroup "RQ2: Polyglot Ingestion Pipelines"
[ bench "Python Pipeline (~100 LOC)" $ nf (\s -> computeBundle "sample.py" smallBytes s) smallSrc
, bench "TypeScript Pipeline (~100 LOC)" $ nf (\s -> computeBundle "sample.ts" tsSmallBytes s) tsSmall
, bench "Go Pipeline (~100 LOC)" $ nf (\s -> computeBundle "sample.go" goSmallBytes s) goSmall
, bench "Rust Pipeline (~100 LOC)" $ nf (\s -> computeBundle "sample.rs" rsSmallBytes s) rsSmall
]
, bgroup "RQ3: Mutation Invariance Processing"
[ bench "Base Code Evaluation" $ nf (computeBundleFromSource "base.py") baseCode
, bench "M1: Whitespace Jitter" $ nf (computeBundleFromSource "m1.py") mutWhitespace
, bench "M2: Comment Churn" $ nf (computeBundleFromSource "m2.py") mutComments
, bench "M3: Internal Body Edit" $ nf (computeBundleFromSource "m3.py") mutBody
]
, bgroup "RQ4: Repository Aggregation Scaling (FR)"
[ bench "10 Files" $ nf computeRepositoryFingerprint repo10
, bench "50 Files" $ nf computeRepositoryFingerprint repo50
, bench "200 Files" $ nf computeRepositoryFingerprint repo200
, bench "500 Files" $ nf computeRepositoryFingerprint repo500
, bench "1,000 Files" $ nf computeRepositoryFingerprint repo1000
]
, bgroup "RQ5: Comparative Baseline Overhead"
[ bench "Raw SHA-256 Hashing (XL)" $ nf computeF0 xlBytes
, bench "AST Parsing Only (XL)" $ nf (parsePythonSource "xl.py") xlSrc
, bench "Canontra Full 8-Tier (XL)" $ nf (\s -> computeBundle "xl.py" xlBytes s) xlSrc
]
, bgroup "RQ6: High-Performance Optimizations (v0.0.4-alpha)"
[ bench "StreamingHash (XL Builder)" $ nf hashBuilderDirect (BB.byteString xlBytes)
, bench "Standard hashBytes (XL)" $ nf hashBytes xlBytes
, bench "Fused Normalization (XL)" $ nf fusedNormalizeProgram xlProg
, bench "Standard Normalization (XL)" $ nf normalizeProgram xlProg
, bench "CompactCFG Conversion (XL)" $ nf (map fromControlFlowGraph . buildCFGs) xlProg
, bench "CompactDFG Conversion (XL)" $ nf (map fromDataFlowGraph . buildDFGs) xlProg
, bench "MerkleCache Lookup (Hit)" $ nf (lookupCache "src/module_1.py" sampleMeta) populatedCache
, bench "Zero-Copy Ingestion (XL)" $ nf (\b -> ingestSource "xl.py" b xlSrc) xlBytes
]
, bgroup "RQ7: v0.0.5-alpha FlatFusion Direct-to-IR Parser Throughput"
[ bgroup "Python Parser"
[ bench "Small (~85 LOC)" $ nf (parsePythonSource "small.py") smallSrc
, bench "Med (~405 LOC)" $ nf (parsePythonSource "med.py") medSrc
, bench "Large (~1605 LOC)" $ nf (parsePythonSource "large.py") largeSrc
]
, bgroup "TypeScript Parser"
[ bench "Small (~85 LOC)" $ nf (parseJSSource "small.ts") tsSmall
, bench "Med (~405 LOC)" $ nf (parseJSSource "med.ts") tsMed
, bench "Large (~1605 LOC)" $ nf (parseJSSource "large.ts") tsLarge
]
, bgroup "Go Parser"
[ bench "Small (~85 LOC)" $ nf (parseGoSource "small.go") goSmall
, bench "Med (~405 LOC)" $ nf (parseGoSource "med.go") goMed
, bench "Large (~1605 LOC)" $ nf (parseGoSource "large.go") goLarge
]
, bgroup "Rust Parser"
[ bench "Small (~85 LOC)" $ nf (parseRustSource "small.rs") rsSmall
, bench "Small BS (~85 LOC)"$ nf (parseRustByteString "small.rs") rsSmallBytes
, bench "Med (~405 LOC)" $ nf (parseRustSource "med.rs") rsMed
, bench "Large (~1605 LOC)" $ nf (parseRustSource "large.rs") rsLarge
]
, bgroup "ByteString SIMD Parsers (v0.4.0)"
[ bench "FastPython BS (Small)" $ nf (parseFastPythonByteString "small.py") smallBytes
, bench "FastPython Src (XL)" $ nf (parseFastPythonSource "xl.py") xlSrc
, bench "JS/TS BS (Small)" $ nf (parseJSByteString "small.ts") tsSmallBytes
, bench "Go BS (Small)" $ nf (parseGoByteString "small.go") goSmallBytes
, bench "Polyglot BS (Py)" $ nf (parsePolyglotByteString "small.py") smallBytes
, bench "Polyglot BS (TS)" $ nf (parsePolyglotByteString "small.ts") tsSmallBytes
]
]
, bgroup "RQ8: SymbolTable Interning & Resolution"
[ bench "Batch Intern 1,000 Identifiers" $ nf (internManyBS sampleIdentifiers) emptySymbolTable
, bench "Single Symbol Intern" $ nf (internSymbolBS "identifier_example") benchSymTable
, bench "SymbolId Lookup (Hit)" $ nf (`resolveSymbolBS` benchSymTable) (SymbolId 42)
, bench "Preloaded Polyglot Lookup" $ nf (`resolveSymbolBS` preloadPolyglotKeywords) (SymbolId 5)
]
, bgroup "RQ9: Selective Outline Mode Speedup for F2 / F3"
[ bgroup "Python Outline"
[ bench "Full AST Parse (Large)" $ nf (parsePythonSource "large.py") largeSrc
, bench "Outline Parse (Large)" $ nf (parseOutlinePython "large.py") largeSrc
, bench "F2 Full AST Compute" $ nf computeF2 largeProg
, bench "F2 Outline Mode Compute" $ nf (\s -> case parseOutlinePython "large.py" s of Right o -> computeF2Outline o; Left _ -> Fingerprint "") largeSrc
, bench "F3 Full AST Compute" $ nf computeF3 largeProg
, bench "F3 Outline Mode Compute" $ nf (\s -> case parseOutlinePython "large.py" s of Right o -> computeF3Outline o; Left _ -> Fingerprint "") largeSrc
]
, bgroup "Polyglot Outline Extraction"
[ bench "TS Outline (Large)" $ nf (parseOutlineJS "large.ts") tsLarge
, bench "Go Outline (Large)" $ nf (parseOutlineGo "large.go") goLarge
, bench "Rust Outline (Large)" $ nf (parseOutlineRust "large.rs") rsLarge
, bench "IngestOutlineSource (Large)"$ nf (\b -> ingestOutlineSource "large.py" b largeSrc) largeBytes
]
]
, bgroup "RQ10: v0.0.6-alpha Hardware-Speed Engines"
[ bgroup "Engine 1: SWAR FastScan"
[ bench "SWAR scanAsciiAndLineEndings (XL)" $ nf scanAsciiAndLineEndings xlBytes
, bench "SWAR fastCanonicalizeBS (XL)" $ nf fastCanonicalizeBS xlBytes
, bench "Standard Unicode canonicalizeText (XL)" $ nf canonicalizeText xlSrc
]
, bgroup "Engine 2: Fused Direct-to-Hash Streaming"
[ bench "fusedHashProgram F1 Direct (XL)" $ nf fusedHashProgram xlProg
, bench "Standard 3-Pass F1 Compute (XL)" $ nf (hashBytes . canonicalizeProgram . normalizeProgram) xlProg
, bench "fusedHashDeclarations F2 Direct (XL)" $ nf (fusedHashDeclarations . extractDeclarations) xlProg
]
, bgroup "Engine 3: Compact Binary Merkle Cache Index (CNTR v2)"
[ bench "encodeBinaryCache (1,000 files)" $ nf encodeBinaryCache largeCache
, bench "decodeBinaryCache (1,000 files)" $ nf decodeBinaryCache largeCacheBin
, bench "lookupBinaryCache O(log N) Hit" $ nf (lookupBinaryCache "src/module_500.py" (FileMetadata "src/module_500.py" 1024 1700000000)) largeCacheBin
, bench "Legacy JSON Aeson Decode (1,000 files)" $ nf (Aeson.decodeStrict :: BS.ByteString -> Maybe MerkleCache) largeCacheJSON
]
, bgroup "Engine 4: Dynamic Work-Stealing Parallel Scheduler"
[ bench "parMapChunks 1,000 Tasks" $ nfIO (parMapChunks pure [1..1000 :: Int])
]
]
, bgroup "RQ11: v0.0.7-alpha Ultra-Low Latency Architecture Engines"
[ bgroup "Engine 1: Radix-Directed Binary Cache (CNTR v3)"
[ bench "lookupBinaryCache Radix Hit (1,000 files)" $ nf (lookupBinaryCache "src/module_500.py" (FileMetadata "src/module_500.py" 1024 1700000000)) largeCacheBin
, bench "encodeBinaryCache with Radix Directory" $ nf encodeBinaryCache largeCache
, bench "decodeBinaryCache v3 (1,000 files)" $ nf decodeBinaryCache largeCacheBin
]
, bgroup "Engine 2: Flat Linear Arena AST"
[ bench "programToLinearAST Linearization (XL)" $ nf programToLinearAST xlProg
, bench "fusedHashLinearAST Direct Arena Hash (XL)" $ nf fusedHashLinearAST xlArena
]
, bgroup "Engine 3: SWAR Direct-to-IR FastPython Parser"
[ bench "parseFastPythonByteString Direct (XL)" $ nf (parseFastPythonByteString "xl.py") xlBytes
, bench "parseFastPythonToArena Direct (XL)" $ nf (parseFastPythonToArena "xl.py") xlSrc
]
, bgroup "Engine 4: Isomorphic Incremental Merkle DAG"
[ bench "buildMerkleDAG (1,000 files)" $ nf buildMerkleDAG repoEntries1000
, bench "merkleDAGRootHash Root Evaluation" $ nf merkleDAGRootHash dag1000
, bench "diffMerkleDAG (1 delta in 1,000 files)" $ nf (diffMerkleDAG dag1000) dag1000Mod
]
, bgroup "Engine 5: SwissTable Open-Addressing Interning"
[ bench "swissInternBS 1,000 Symbols" $ nf (\ids -> foldl' (\(_, tbl) bs -> swissInternBS tbl bs) (SymbolId 0, emptySwissTable 1024) ids) sampleIdentifiers
, bench "swissLookupBS Hit" $ nf (swissLookupBS benchSwissTable) "identifier_500"
, bench "swissResolveId Inverse Lookup" $ nf (swissResolveId benchSwissTable) (SymbolId 500)
]
]
, bgroup "RQ12: v0.0.9-alpha Whole-Repo Intelligence & Verification"
[ bgroup "Engine 1: Whole-Repo Call Graph (F_WCG)"
[ bench "buildWholeRepoCallGraph (10 modules)" $ nf buildWholeRepoCallGraph modules10
, bench "computeFWCG (10 modules)" $ nf computeFWCG modules10
]
, bgroup "Engine 2: Whole-Repo Inter-Procedural Data-Flow (F_WDF)"
[ bench "buildWholeRepoDataFlow (10 modules)" $ nf buildWholeRepoDataFlow modules10
, bench "computeFWDF (10 modules)" $ nf computeFWDF modules10
]
, bgroup "Engine 3: Semantic Change Impact Slicing (CIA)"
[ bench "classifySeverity (Interface Mutation)" $ nf (classifySeverity (feFingerprints sampleBundle)) (feFingerprints (head repo1000))
, bench "computeImpactSlice (10 modules)" $ nf (\b -> computeImpactSlice "src/module_1.py" (feFingerprints sampleBundle) b wcg10 (map fst modules10)) (feFingerprints (head repo1000))
]
, bgroup "Engine 4: Structural Type Contract Invariance (F_T)"
[ bench "extractTypeContracts (XL)" $ nf extractTypeContracts xlProg
, bench "computeFT (XL)" $ nf computeFT xlProg
]
, bgroup "Engine 5: Memory-Mapped Paged Radix Cache (CNTR v5)"
[ bench "encodeBinaryCacheV5 (1,000 files)" $ nf encodeBinaryCacheV5 largeCache
, bench "decodeBinaryCacheV5 (1,000 files)" $ nf decodeBinaryCacheV5 largeCacheV5Bin
, bench "lookupBinaryCacheV5 Hit" $ nf (lookupBinaryCacheV5 "src/module_500.py" (FileMetadata "src/module_500.py" 1024 1700000000)) largeCacheV5Bin
]
, bgroup "Engine 6: Metamorphic Mutation & Verification"
[ bench "verifyMetamorphicProgramTransform (XL)"$ nf (`verifyMetamorphicProgramTransform` (ReformatWhitespaceTrivia 4)) xlProg
, bench "verifyProgramMutation (XL)" $ nf (`verifyProgramMutation` (MutFlipArithmeticOp OpAdd OpSub)) xlProg
, bench "runMetamorphicSuite (Polyglot Corpus)" $ nf runMetamorphicSuite polyglotFixtures
]
]
, bgroup "RQ13: v0.2.0 Unboxed CSR Graph Engine"
[ bgroup "Engine 1: CSR Construction & Query"
[ bench "buildCSRGraph (100 nodes, 500 edges)" $ nf (buildCSRGraph 100) csrEdges500
, bench "csrHasEdge Binary Search (Hit)" $ nf (\g -> csrHasEdge g 10 37) csrGraph100
, bench "transposeCSR Linear Transpose" $ nf transposeCSR csrGraph100
, bench "tarjanSCC Cycle Detection" $ nf tarjanSCC csrGraph100
, bench "condenseSCC Canonical DAG" $ nf condenseSCC csrGraph100
, bench "forwardReachabilityCone (100 nodes)" $ nf (\g -> forwardReachabilityCone g [10]) csrGraph100
]
, bgroup "Engine 2: Whole-Repo CSR Synthesis"
[ bench "buildCSRCallGraph (10 modules)" $ nf buildCSRCallGraph modules10
, bench "buildCSRDataFlow (10 modules)" $ nf buildCSRDataFlow modules10
]
]
, bgroup "RQ14: v0.2.0 CNTR\\x06 Zero-Copy Memory-Mapped Slab Cache"
[ bench "encodeSlabV6Binary (1,000 files)" $ nf (`encodeSlabV6Binary` Nothing) slabEntries1000
, bench "decodeSlabV6Binary (1,000 files)" $ nf decodeSlabV6Binary slabV6Bin
, bench "lookupSlabBinaryBS Zero-Copy Warm Hit" $ nf (\bs -> lookupSlabBinaryBS "src/module_500.py" (FileMetadata "src/module_500.py" 1024 1700000000) bs) slabV6Bin
, bench "encodeCSRGraph Binary Serialization" $ nf (LBS.toStrict . BB.toLazyByteString . encodeCSRGraph) csrGraph100
, bench "decodeCSRGraph Binary Deserialization" $ nf decodeCSRGraph csrEncodedBS
]
, bgroup "RQ15: v0.2.0 SIMD FastScan & Chase-Lev Work-Stealing"
[ bgroup "Engine 1: 256-Bit Hardware SIMD Scan"
[ bench "scanSourceSIMD 256-Bit (XL)" $ nf scanSourceSIMD xlBytes
, bench "isPureAsciiUnixSIMD FastPath (XL)" $ nf isPureAsciiUnixSIMD xlBytes
, bench "fastCanonicalizeSIMD (XL)" $ nf fastCanonicalizeSIMD xlBytes
]
, bgroup "Engine 2: Chase-Lev Lock-Free Work-Stealing"
[ bench "Chase-Lev Deque Push/Pop/Steal" $ nfIO $ do
dq <- newChaseLevDeque (100 :: Int)
mapM_ (pushBottom dq) [1..100 :: Int]
_ <- stealBatchTop dq 10
_ <- popBottom dq
pure ()
, bench "parProcessWorkStealing (1,000 tasks)" $ nfIO $ parProcessWorkStealing (\x -> pure (x * (2 :: Int))) [1..1000 :: Int]
]
, bgroup "Engine 3: Localized Incremental Graph Delta"
[ bench "spliceCSREdges Localized Invalidation" $ nf (\g -> spliceCSREdges g [10] [(10, 20, 1)]) csrGraph100
, bench "incrementalUpdateWholeRepoGraphs (10 modules)" $ nf (\mods -> incrementalUpdateWholeRepoGraphs wcg10Graph wdf10Graph mods ["src/module_1.py"]) modules10
]
]
, bgroup "RQ16: v0.3.0 Bound Alpha-Canonicalization & CFG RPO"
[ bench "canonicalizeAlphaProgram (Medium)" $ nf canonicalizeAlphaProgram medProg
, bench "canonicalizeAlphaProgram (XL)" $ nf canonicalizeAlphaProgram xlProg
, bench "canonicalizeCFGRPO (XL)" $ nf (map canonicalizeCFGRPO . buildCFGs) xlProg
]
, bgroup "RQ17: v0.3.0 Algebraic Normalization & CSR Batch CIA 2.0"
[ bench "normalizeAlgebraicProgram (Medium)" $ nf normalizeAlgebraicProgram medProg
, bench "normalizeAlgebraicProgram (XL)" $ nf normalizeAlgebraicProgram xlProg
, bench "computeImpactSliceCSR (10 modules)" $ nf (\b -> computeImpactSliceCSR "src/module_1.py" (feFingerprints sampleBundle) b csrPair10 (map fst modules10)) (feFingerprints (head repo1000))
, bench "computeBatchImpactSliceCSR (PR batch)" $ nf (\b -> computeBatchImpactSliceCSR [("src/module_1.py", feFingerprints sampleBundle, b)] csrPair10 (map fst modules10)) (feFingerprints (head repo1000))
]
, bgroup "RQ18: v0.4.0 SlabV7 & Summary Synthesis"
[ bench "encodeSlabV7Binary (10 modules)" $ nf (`encodeSlabV7Binary` Nothing) slabV7Entries10
, bench "decodeSlabV7Binary (10 modules)" $ nf decodeSlabV7Binary slabV7Bin10
, bench "lookupSlabV7BinaryBS (Warm Hit)" $ nf (lookupSlabV7BinaryBS "src/module_1.py" (FileMetadata "src/module_1.py" 1024 1700000000)) slabV7Bin10
, bench "buildWholeRepoCallGraphFromSummaries (10 mods)" $ nf buildWholeRepoCallGraphFromSummaries summaries10
, bench "buildWholeRepoDataFlowFromSummaries (10 mods)" $ nf buildWholeRepoDataFlowFromSummaries summaries10
]
, bgroup "RQ19: v0.4.0 Stateless AI Harness Sub-Versioning (canontra snap)"
[ bench "diffFileBundles (9-tier bundle comparison)" $ nf (diffFileBundles (feFingerprints sampleBundle)) dummyBundleM
, bench "computeFileDeltas (1,000 files, 1 dirty)" $ nf (computeFileDeltas snapMap1000) snapMap1000Mod
, bench "classifySnapDeltas (dirty delta triage)" $ nf classifySnapDeltas snapDirtyDeltas
, bench "parseGuardTiers (F2,F3,F_T)" $ nf parseGuardTiers "F2,F3,F_T"
, bench "matchesGlob (**/*.py)" $ nf (matchesGlob "**/*.py") "src/module_500.py"
]
]
_ -> putStrLn "Error initializing benchmark source fixtures."