-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline
ASTNode
bindings dependencies and observers (#15098)
Every `ASTNode` contains two arrays used for type inference and checking: dependencies and observers. By default, these are created lazily, but most active (ie. effectively typed) `ASTNode`s end up creating them. Furthermore, on average both these lists contain less than 2 elements each. This PR replaces both `Array(ASTNode)?` references in `ASTNode` by inlined structs that can hold two elements and a tail array for the cases where more links are needed. This reduces the number of allocations, bytes allocated, number of instructions executed and running time. Some numbers from compiling the Crystal compiler itself without running codegen (since type binding occurs in the semantic phase anyway). * Running time (measured with hyperfine running with `GC_DONT_GC=1`): ~6% reduction Before: ``` Benchmark 1: ./self-semantic-only.sh Time (mean ± σ): 3.398 s ± 0.152 s [User: 2.264 s, System: 0.470 s] Range (min … max): 3.029 s … 3.575 s 10 runs ``` After: ``` Benchmark 1: ./self-semantic-only.sh Time (mean ± σ): 3.180 s ± 0.095 s [User: 2.153 s, System: 0.445 s] Range (min … max): 3.046 s … 3.345 s 10 runs ``` * Memory (as reported by the compiler itself, with GC): ~9.6% reduction Before: ``` Parse: 00:00:00.000038590 ( 1.05MB) Semantic (top level): 00:00:00.483357706 ( 174.13MB) Semantic (new): 00:00:00.002156811 ( 174.13MB) Semantic (type declarations): 00:00:00.038313066 ( 174.13MB) Semantic (abstract def check): 00:00:00.014283169 ( 190.13MB) Semantic (restrictions augmenter): 00:00:00.010672651 ( 206.13MB) Semantic (ivars initializers): 00:00:04.660611385 (1250.07MB) Semantic (cvars initializers): 00:00:00.008343907 (1250.07MB) Semantic (main): 00:00:00.780627942 (1346.07MB) Semantic (cleanup): 00:00:00.000961914 (1346.07MB) Semantic (recursive struct check): 00:00:00.001121766 (1346.07MB) ``` After: ``` Parse: 00:00:00.000044417 ( 1.05MB) Semantic (top level): 00:00:00.546445955 ( 190.03MB) Semantic (new): 00:00:00.002488975 ( 190.03MB) Semantic (type declarations): 00:00:00.040234541 ( 206.03MB) Semantic (abstract def check): 00:00:00.015473723 ( 222.03MB) Semantic (restrictions augmenter): 00:00:00.010828366 ( 222.03MB) Semantic (ivars initializers): 00:00:03.324639987 (1135.96MB) Semantic (cvars initializers): 00:00:00.007359853 (1135.96MB) Semantic (main): 00:00:01.806822202 (1217.96MB) Semantic (cleanup): 00:00:00.000626975 (1217.96MB) Semantic (recursive struct check): 00:00:00.001435494 (1217.96MB) ``` * Callgrind stats: - Instruction refs: 17,477,865,704 -> 16,712,610,033 (~4.4% reduction) - Estimated cycles: 26,835,733,874 -> 26,154,926,143 (~2.5% reduction) - `GC_malloc_kind` call count: 35,161,616 -> 25,684,997 (~27% reduction) Co-authored-by: Oleh Prypin <[email protected]> Co-authored-by: Johannes Müller <[email protected]>
- Loading branch information
1 parent
8237397
commit 9d8c2e4
Showing
6 changed files
with
97 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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