From 198567a987ec6aa41a232660a0f9c2c6a04b6625 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 17 Dec 2019 13:47:16 -0500 Subject: [PATCH] enable inline allocation of structs with pointers --- NEWS.md | 10 ++++++++++ src/datatype.c | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7aeb6f927804d..1b93de742b77a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -72,6 +72,16 @@ Language changes * Color now defaults to on when stdout and stderr are TTYs ([#34347]) +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`. + Multi-threading changes ----------------------- 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;