From 47a5815070a8ebf4ce1e00de0a44863fd9c1fb84 Mon Sep 17 00:00:00 2001 From: Zubin Duggal Date: Wed, 10 May 2023 15:46:11 +0530 Subject: testsuite: add test for T22744 This test checks for #22744 by compiling 100 modules which each have a dependency on 1000 distinct external files. Previously, when loading these interfaces from disk, each individual instance of a filepath in the interface will would be allocated as an individual object on the heap, meaning we have heap objects for 100*1000 files, when there are only 1000 distinct files we care about. This test checks this by first compiling the module normally, then measuring the peak memory usage in a no-op recompile, as the recompilation checking will force the allocation of all these filepaths. --- testsuite/tests/perf/compiler/Makefile | 5 +++++ testsuite/tests/perf/compiler/all.T | 11 +++++++++++ testsuite/tests/perf/compiler/genT22744 | 28 ++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 testsuite/tests/perf/compiler/genT22744 diff --git a/testsuite/tests/perf/compiler/Makefile b/testsuite/tests/perf/compiler/Makefile index 762883b0b4..06f9ac1304 100644 --- a/testsuite/tests/perf/compiler/Makefile +++ b/testsuite/tests/perf/compiler/Makefile @@ -32,3 +32,8 @@ MultiLayerModulesTH_OneShot_Prep: MultiLayerModulesTH_Make_Prep InstanceMatching: ./genMatchingTest 0 '$(TEST_HC)' $(TEST_HC_OPTS) -fno-code -fwrite-interface Defs.hs + +T22744: + ./genT22744 + '$(TEST_HC)' $(TEST_HC_OPTS) T22744.hs + diff --git a/testsuite/tests/perf/compiler/all.T b/testsuite/tests/perf/compiler/all.T index 14cd4cce94..56729a6e3f 100644 --- a/testsuite/tests/perf/compiler/all.T +++ b/testsuite/tests/perf/compiler/all.T @@ -670,3 +670,14 @@ test('RecordUpdPerf', ], multimod_compile, ['RecordUpdPerf', '-fno-code -v0']) + +test('T22744', + [ collect_compiler_stats('peak_megabytes_allocated',20), + req_interp, + pre_cmd('$MAKE -s --no-print-directory T22744'), + extra_files(['genT22744']), + compile_timeout_multiplier(2) + ], + multimod_compile, + ['T22744', '-v0']) + diff --git a/testsuite/tests/perf/compiler/genT22744 b/testsuite/tests/perf/compiler/genT22744 new file mode 100755 index 0000000000..fdbe1fcefb --- /dev/null +++ b/testsuite/tests/perf/compiler/genT22744 @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +NUMDEP=10000 +NUMMOD=100 + +seq 1 $NUMDEP | xargs -I{} touch foo{} + +cat > T22744.hs << EOF +module Main where +EOF + +for i in $(seq $NUMMOD); do + cat > M$i.hs << EOF +{-# LANGUAGE TemplateHaskell #-} +module M$i where +import Language.Haskell.TH.Syntax +import Control.Monad + +\$(do forM_ [1..$NUMDEP] $ \i -> addDependentFile $ "foo" ++ show i + return []) +EOF + echo "import M$i" >> T22744.hs +done + +cat >> T22744.hs << EOF +main = pure () +EOF + -- cgit v1.2.1