From 8073ddfbb4406eb456d8e5a3e48acf4d48574da5 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 27 Apr 2020 13:20:12 -0400 Subject: [PATCH] enable inline allocation of structs with pointers (#34126) --- NEWS.md | 13 ++++++++++--- src/datatype.c | 9 ++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/NEWS.md b/NEWS.md index d9bc676650155..373bbd3b55327 100644 --- a/NEWS.md +++ b/NEWS.md @@ -70,6 +70,16 @@ Language changes * The line number of function definitions is now added by the parser as an additional `LineNumberNode` at the start of each function body ([#35138]). +Compiler/Runtime improvements +----------------------------- + +* Immutable structs (including tuples) that contain references can now be allocated + on the stack, and allocated inline within arrays and other structs ([#33886]). + This significantly reduces the number of heap allocations in some workloads. + Code that requires assumptions about object layout and addresses (usually for + interoperability with C or other languages) might need to be updated; for + example any object that needs a stable address should be a `mutable struct`. + Command-line option changes --------------------------- @@ -79,9 +89,6 @@ Command-line option changes * Color now defaults to on when stdout and stderr are TTYs ([#34347]) -Command-line option changes ---------------------------- - * `-t N`, `--threads N` starts Julia with `N` threads. This option takes precedence over `JULIA_NUM_THREADS`. The specified number of threads also propagates to worker processes spawned using the `-p`/`--procs` or `--machine-file` command line arguments. diff --git a/src/datatype.c b/src/datatype.c index 15bdb8e6aa464..b2b1731c12c7a 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -506,11 +506,10 @@ void jl_compute_field_offsets(jl_datatype_t *st) // now finish deciding if this instantiation qualifies for special properties assert(!isbitstype || st->layout->npointers == 0); // the definition of isbits if (isinlinealloc && st->layout->npointers > 0) { - //if (st->ninitialized != nfields) - // isinlinealloc = 0; - //else if (st->layout->fielddesc_type != 0) // GC only implements support for this - // isinlinealloc = 0; - isinlinealloc = 0; + if (st->ninitialized != nfields) + isinlinealloc = 0; + else if (st->layout->fielddesc_type != 0) // GC only implements support for this + isinlinealloc = 0; } st->isbitstype = isbitstype; st->isinlinealloc = isinlinealloc;