[Git][ghc/ghc][wip/specialise-assembler] 18 commits: perf: Replace uses of genericLength with strictGenericLength
Matthew Pickering (@mpickering)
gitlab at gitlab.haskell.org
Mon Feb 10 10:50:50 UTC 2025
Matthew Pickering pushed to branch wip/specialise-assembler at Glasgow Haskell Compiler / GHC
Commits:
db19c8a9 by Matthew Pickering at 2025-02-05T23:16:50-05:00
perf: Replace uses of genericLength with strictGenericLength
genericLength is a recursive function and marked NOINLINE. It is not
going to specialise. In profiles, it can be seen that 3% of total compilation
time when computing bytecode is spend calling this non-specialised
function.
In addition, we can simplify `addListToSS` to avoid traversing the input
list twice and also allocating an intermediate list (after the call to
reverse).
Overall these changes reduce the time spend in 'assembleBCOs' from 5.61s
to 3.88s. Allocations drop from 8GB to 5.3G.
Fixes #25706
- - - - -
5622a14a by Matthew Pickering at 2025-02-05T23:17:27-05:00
perf: nameToCLabel: Directly manipulate ByteString rather than going via strings
`nameToCLabel` is called from `lookupHsSymbol` many times during
bytecode linking. We can save a lot of allocations and time by directly
manipulating the bytestrings rather than going via intermediate lists.
Before: 2GB allocation, 1.11s
After: 260MB allocation, 375ms
Fixes #25719
-------------------------
Metric Decrease:
MultiLayerModulesTH_OneShot
-------------------------
- - - - -
66c7f656 by Matthew Pickering at 2025-02-06T17:15:25-05:00
interpreter: Fix INTERP_STATS profiling code
The profiling code had slightly bitrotted since the last time it was
used. This just fixes things so that if you toggle the INTERP_STATS
macro then it just works and prints out the stats.
Fixes #25695
- - - - -
f71c2835 by Matthew Pickering at 2025-02-06T17:16:02-05:00
perf: Key the interpreter symbol cache by Name rather than FastString
Profiles showed that about 0.2s was being spend constructing the keys
before looking up values in the old symbol cache.
The performance of this codepath is critical as it translates directly
to a delay when a user evaluates a function like `main` in the
interpreter.
Therefore we implement a solution which keys the cache(s) by `Name`
rather than the symbol directly, so the cache can be consulted before
the symbol is constructed.
Fixes #25731
- - - - -
8f8d3a90 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label threads forked by IO operations
Addresses part of #25452.
Addresses core-libraries-committee#305.
- - - - -
28600825 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label threads forked by System.Timeout
Addresses part of #25452.
Addresses core-libraries-committee#305.
- - - - -
8a249827 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label signal handling threads
Addresses part of #25452.
Addresses core-libraries-committee#305.
- - - - -
26af26f0 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Label Windows console event handling threads
Addresses part of #25452.
Addresses core-libraries-committee#305.
- - - - -
bf9c3d4f by Ben Gamari at 2025-02-08T01:17:28-05:00
ghci: Label evaluation sandbox thread
Addresses part of #25452.
Addresses core-libraries-committee#305.
- - - - -
38f78ce5 by Ben Gamari at 2025-02-08T01:17:28-05:00
base: Add changelog entry for addition of thread labels
Addresses #25452.
Addresses core-libraries-committee#305.
- - - - -
c100deb5 by Ben Gamari at 2025-02-08T01:18:05-05:00
gen-ci: Clean up style
This cleans up a number of stylistic inconsistencies although it's still
far from perfect.
- - - - -
c4a7680a by Ben Gamari at 2025-02-08T01:18:05-05:00
gen-ci: Properly encapsulate GitLab predicates
- - - - -
52b6539b by M Farkas-Dyck at 2025-02-08T11:34:51-08:00
Avoid partiality in `Language.Haskell.Syntax.Expr`, `GHC.Hs.Expr`, `GHC.Rename.Expr`, etc.
In particular, use `NonEmpty` where appropriate:
- the argument of `FieldLabelString`
- the argument of `HsMultiIf`
- `grhssGRHSs`
Decreases overall compile-time allocation by about 0.1% in the benchmark suite (min -0.8%, max +0.3%).
Metric Decrease:
T3294
- - - - -
a566da92 by Ben Gamari at 2025-02-10T03:21:49-05:00
gitlab-ci: Bump docker images
Closes #25693.
- - - - -
a7e23f01 by Ben Gamari at 2025-02-10T03:21:49-05:00
hadrian: Drop uses of head/tail
To silence warnings with GHC 9.10
- - - - -
12752f0c by Ben Gamari at 2025-02-10T03:21:49-05:00
hadrian: Disable x-data-list-nonempty-unzip warning
- - - - -
151fc8ea by Sven Tennie at 2025-02-10T10:50:30+00:00
Do not deallocate stack for jump/switch table jumps
Though the name is misleading, we consider them to be branching. For
branch instructions we do not deallocate (parts of) the stack, but keep
the stack pointer (sp) intact.
- - - - -
02a02983 by Matthew Pickering at 2025-02-10T10:50:30+00:00
perf: Speed up the bytecode assembler
This commit contains a number of optimisations to the bytecode
assembler. In programs which generate a large amount of bytecode, the
assembler is called a lot of times on many instructions.
1. Specialise the assembleI function for the two intepreters to avoid
having to materialise the intermediate free-monad like structure.
2. Directly compute the UArray and SmallArray needed rather than going
via the intermediate SizedSeq
3. Use optimised monads
4. Define unrolled "any" and "mapM6" functions which can be inlined
and avoid calling recursive functions.
The resulting generated code is much more direct.
Before:
./ByteCodeAsm /home/matt/ghc-profiling-light/_build/stage1/lib/ +RTS -s
48,923,125,664 bytes allocated in the heap
678,221,152 bytes copied during GC
395,648 bytes maximum residency (2 sample(s))
50,040 bytes maximum slop
6 MiB total memory in use (0 MiB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 11731 colls, 0 par 0.419s 0.425s 0.0000s 0.0004s
Gen 1 2 colls, 0 par 0.001s 0.001s 0.0007s 0.0012s
INIT time 0.000s ( 0.000s elapsed)
MUT time 6.466s ( 6.484s elapsed)
GC time 0.421s ( 0.426s elapsed)
EXIT time 0.000s ( 0.000s elapsed)
Total time 6.887s ( 6.910s elapsed)
After:
1,518,321,200 bytes allocated in the heap
4,299,552 bytes copied during GC
322,288 bytes maximum residency (2 sample(s))
50,280 bytes maximum slop
6 MiB total memory in use (0 MiB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 369 colls, 0 par 0.003s 0.003s 0.0000s 0.0002s
Gen 1 2 colls, 0 par 0.001s 0.001s 0.0007s 0.0012s
INIT time 0.001s ( 0.001s elapsed)
MUT time 0.465s ( 0.466s elapsed)
GC time 0.004s ( 0.004s elapsed)
EXIT time 0.000s ( 0.000s elapsed)
Total time 0.470s ( 0.471s elapsed)
- - - - -
84 changed files:
- .gitlab-ci.yml
- .gitlab/generate-ci/gen_ci.hs
- compiler/GHC.hs
- compiler/GHC/ByteCode/Asm.hs
- compiler/GHC/ByteCode/Instr.hs
- compiler/GHC/ByteCode/Linker.hs
- compiler/GHC/ByteCode/Types.hs
- compiler/GHC/CmmToAsm/AArch64/Instr.hs
- compiler/GHC/Core/UsageEnv.hs
- compiler/GHC/Data/FlatBag.hs
- + compiler/GHC/Data/List/NonEmpty.hs
- compiler/GHC/Data/SmallArray.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Arrows.hs
- compiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/GuardedRHSs.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Ticks.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Parser.y
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Prelude/Basic.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Runtime/Interpreter.hs
- compiler/GHC/Runtime/Interpreter/Types.hs
- + compiler/GHC/Runtime/Interpreter/Types/SymbolCache.hs
- compiler/GHC/StgToByteCode.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- compiler/ghc.cabal.in
- hadrian/src/Hadrian/Utilities.hs
- hadrian/src/Oracles/ModuleFiles.hs
- hadrian/src/Rules/Dependencies.hs
- hadrian/src/Settings/Parser.hs
- libraries/base/changelog.md
- libraries/base/src/Control/Concurrent.hs
- libraries/base/src/System/Timeout.hs
- libraries/ghc-boot/GHC/Data/SizedSeq.hs
- libraries/ghc-internal/src/GHC/Internal/Conc/Signal.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Windows/ConsoleEvent.hsc
- libraries/ghci/GHCi/Run.hs
- rts/Interpreter.c
- rts/Interpreter.h
- rts/RtsMain.c
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/ghc-api/exactprint/T22919.stderr
- testsuite/tests/ghc-api/exactprint/ZeroWidthSemi.stderr
- testsuite/tests/interface-stability/base-exports.stdout
- testsuite/tests/interface-stability/base-exports.stdout-javascript-unknown-ghcjs
- testsuite/tests/interface-stability/base-exports.stdout-mingw32
- testsuite/tests/interface-stability/base-exports.stdout-ws-32
- testsuite/tests/module/mod185.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpParsedAstComments.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/DumpSemis.stderr
- testsuite/tests/parser/should_compile/DumpTypecheckedAst.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- testsuite/tests/parser/should_compile/T20718.stderr
- testsuite/tests/parser/should_compile/T20846.stderr
- testsuite/tests/perf/compiler/hard_hole_fits.stderr
- + testsuite/tests/perf/should_run/ByteCodeAsm.hs
- testsuite/tests/perf/should_run/all.T
- testsuite/tests/printer/Test20297.stdout
- testsuite/tests/printer/Test24533.stdout
- + testsuite/tests/th/EmptyGuard.hs
- + testsuite/tests/th/EmptyGuard.stderr
- testsuite/tests/th/all.T
- utils/check-exact/ExactPrint.hs
- utils/check-exact/Transform.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2ec5a1a6079a96472af98d56d3bffaef85eabebf...02a0298369636c1a90e1d5199a58c51abc0df63d
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/2ec5a1a6079a96472af98d56d3bffaef85eabebf...02a0298369636c1a90e1d5199a58c51abc0df63d
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20250210/62e3edcc/attachment-0001.html>
More information about the ghc-commits
mailing list