diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-08-19 17:52:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-08-19 17:52:22 -0700 |
| commit | 9ec9c0f5e57820f4baa04b9674a6a4a88235b863 (patch) | |
| tree | 31f0da7dad51bcf707cba8555d7aa33f0ab0a1ba /src/analyze.cpp | |
| parent | 5fdcb1a792e271c67f3aec36f8aca9e6c5503013 (diff) | |
| download | zig-9ec9c0f5e57820f4baa04b9674a6a4a88235b863.tar.gz zig-9ec9c0f5e57820f4baa04b9674a6a4a88235b863.zip | |
optimize the memory layout of Module.Fn and Module.Var
`is_pub` added to `Fn` would cost us an additional 8
bytes of memory per function, which is a real bummer
since it's only 1 bit of information.
If we wanted to really remove this, I suspect we could
make this a function isPub() which looks at the AST of
the corresponding Decl and finds if the FnProto AST node
has the pub token. However I saw an easier approach -
The data of whether something is pub or not is actually
a property of a Decl anyway, not a function, so we can
look at moving the field into Decl. Indeed, doing this,
we see that Decl already has deletion_flag: bool which
is hiding in the padding bytes between the enum (1 byte)
and the following u32 field (generation). So if we put
the is_pub bool there, it actually will take up no
additional space, with 1 byte of padding remaining.
This was an easy reworking of the code since any
func.is_pub could be changed simply to func.owner_decl.is_pub.
I also modified `Var` to make the init value non-optional
and moved the optional bit to a has_init: bool field. This is worse from
the perspective of control flow and safety, however it makes
`@sizeOf(Var)` go from 32 bytes to 24 bytes. The more code we can fit
into memory at once, the more justified we are in using the compiler as
a long-running process that does incremental updates.
Diffstat (limited to 'src/analyze.cpp')
0 files changed, 0 insertions, 0 deletions
