Skip to content

Commit 8073ddf

Browse files
authored
enable inline allocation of structs with pointers (#34126)
1 parent 7d27fa8 commit 8073ddf

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

NEWS.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ Language changes
7070
* The line number of function definitions is now added by the parser as an
7171
additional `LineNumberNode` at the start of each function body ([#35138]).
7272

73+
Compiler/Runtime improvements
74+
-----------------------------
75+
76+
* Immutable structs (including tuples) that contain references can now be allocated
77+
on the stack, and allocated inline within arrays and other structs ([#33886]).
78+
This significantly reduces the number of heap allocations in some workloads.
79+
Code that requires assumptions about object layout and addresses (usually for
80+
interoperability with C or other languages) might need to be updated; for
81+
example any object that needs a stable address should be a `mutable struct`.
82+
7383
Command-line option changes
7484
---------------------------
7585

@@ -79,9 +89,6 @@ Command-line option changes
7989

8090
* Color now defaults to on when stdout and stderr are TTYs ([#34347])
8191

82-
Command-line option changes
83-
---------------------------
84-
8592
* `-t N`, `--threads N` starts Julia with `N` threads. This option takes precedence over
8693
`JULIA_NUM_THREADS`. The specified number of threads also propagates to worker
8794
processes spawned using the `-p`/`--procs` or `--machine-file` command line arguments.

src/datatype.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,10 @@ void jl_compute_field_offsets(jl_datatype_t *st)
506506
// now finish deciding if this instantiation qualifies for special properties
507507
assert(!isbitstype || st->layout->npointers == 0); // the definition of isbits
508508
if (isinlinealloc && st->layout->npointers > 0) {
509-
//if (st->ninitialized != nfields)
510-
// isinlinealloc = 0;
511-
//else if (st->layout->fielddesc_type != 0) // GC only implements support for this
512-
// isinlinealloc = 0;
513-
isinlinealloc = 0;
509+
if (st->ninitialized != nfields)
510+
isinlinealloc = 0;
511+
else if (st->layout->fielddesc_type != 0) // GC only implements support for this
512+
isinlinealloc = 0;
514513
}
515514
st->isbitstype = isbitstype;
516515
st->isinlinealloc = isinlinealloc;

0 commit comments

Comments
 (0)