Zulip Chat Archive
Stream: lean4
Topic: Arrays in lean runtime
Callan McGill (Jun 15 2022 at 02:56):
I was wondering if arrays in the lean4 runtime are all boxed or if they used an optimal layout based on the argument type?
James Gallicchio (Jun 15 2022 at 03:01):
scalar arrays (e.g. Array Byte
, Array Float
, ...) have specialized array impls, but everything else is an array of lean_object*
s. so if you have a generic function operating on generic arrays, everything will end up in a lean_object*
box which may not be the optimal layout
Callan McGill (Jun 15 2022 at 03:05):
so just to check, if I used a something like Array.sequenceMap
over a scalar array, that is going to produce reasonable code?
James Gallicchio (Jun 15 2022 at 03:08):
I have no clue :sweat_smile: a lot of things can get in the way of producing optimized bytecode. From what I've heard, getting leanc to produce a very optimized binary can be hard
Mario Carneiro (Jun 15 2022 at 03:11):
I don't think Array Byte
has a specialized layout. (Instead there is a separate type ByteArray
)
Mario Carneiro (Jun 15 2022 at 03:11):
Array A
always has boxed cells
Mario Carneiro (Jun 15 2022 at 03:12):
Many array functions are @[specialize]
d to the types they get used at though, so it's not always generic code
Mario Carneiro (Jun 15 2022 at 03:13):
the best way to find out is to just compile it and inspect the generated C code (which isn't too hard to follow once you get used to it)
James Gallicchio (Jun 15 2022 at 03:14):
Mario Carneiro said:
I don't think
Array Byte
has a specialized layout. (Instead there is a separate typeByteArray
)
Ahh, I thought the type constructor itself was specialized. Sorry for the misinformation @Callan McGill
Callan McGill (Jun 15 2022 at 03:16):
No worries, it was otherwise useful info.
Gabriel Ebner (Jun 15 2022 at 08:02):
There are separate ByteArray
and FloatArray
types if you need unboxed arrays.
Last updated: Dec 20 2023 at 11:08 UTC