OCaml Locals Save Allocations | OCaml Unboxed

  Рет қаралды 2,167

Jane Street

Jane Street

Күн бұрын

Пікірлер: 12
@alicaglayanrulzok
@alicaglayanrulzok 11 ай бұрын
So is the plan to make this inferred by the compiler? Otherwise it seems like a lot of hassle unless you have some hotspots you want to speed up.
@goodnight_noom
@goodnight_noom 10 ай бұрын
But then does it mean that for functions we want to explicitly type we wont benefit from the inferred locality and have to go through the hassle anyway?
@RichardEisenberg-JS
@RichardEisenberg-JS 10 ай бұрын
This is a bit subtle. We're not going to infer exclaves, because doing so can change the asymptotic runtime of your program. (Actually, I should make a video about that. But not for a few weeks!) We can infer everything else -- but (as @goodnight_noom suggests) every time you write a type, you potentially interrupt that inference. So it really is some hassle. And yet my colleagues here at Jane Street are happy to put in the time adding the annotations to get their speedup. The whole system is opt-in, so indeed you'd probably only want to do this where it really counts.
@pdp11
@pdp11 10 ай бұрын
@@RichardEisenberg-JS Why can't there be mode inference even if you specify the types? Why does specifying a type without a mode annotation mean it's global?
@RichardEisenberg-JS
@RichardEisenberg-JS 10 ай бұрын
@@pdp11 I suppose we could have something like `_ t1 -> _ t2` that indicates we should infer the mode. (Well, not that syntax.) But we need to know what `t1 -> t2` means: is it saying global implicitly? Or does it want inference? Right now, if you write a type, its modes are considered known. (This has to be the case in interface files, regardless of what we do on function annotations.)
@mndrix
@mndrix 8 ай бұрын
It seems like a lot of type annotations. I wonder if the escape analysis could be done beneath the covers so it doesn't surface through the types. I recall Go's escape analysis being pretty good without guidance like this. I'm probably missing something.
@RichardEisenberg-JS
@RichardEisenberg-JS 8 ай бұрын
Most of the annotations here aren't necessary. They're there to make everything more explicit for the video. The `exclave_`s are necessary, but nothing else. Marking lcoals in mli files is necessary though, to enable separate compilation.
@MirceaPricop
@MirceaPricop 10 ай бұрын
Why do the contents of a local_ list have to also be local_? I feel like that was glanced over but it's not obvious to me. What would be the problem if the argument to iter leaks a reference to a list element? We can still clean up the list itself at the end of the region, right?
@RichardEisenberg-JS
@RichardEisenberg-JS 10 ай бұрын
Spot on, yes. In general, we have a free choice here: we could say (A) that the contents of a local list are local or (B) the contents of a local list are global. (A) means that we can store local things in a list but we can't let the contents of a local list escape; (B) means that we can let the contents of a local list escape, but we can't store local things in a list. We can't have both. But we can, actually, via a thing called the global modality. We'll get there in a few videos. In brief, it allows you to label a field of a structure as acting like (B). So you get an (A)-list (the normal list type) and a (B)-list (something you'd have to write yourself). These would be different types. This is a bit annoying, for sure, but having one type that can both store local things and then let them escape is definitely worse!
@a_external_ways.fully_arrays
@a_external_ways.fully_arrays 10 ай бұрын
Hmm, so this was just to solve for simple functions like iter and init, where even here, I find the process too complex by itself - imagine doing this for complex functions, and depending on libraries that doesn't support locals. Also, my guess is that this will make people copy other libraries code to their own codebase, to add locals support - so it breaks the modularity of libraries
@RichardEisenberg-JS
@RichardEisenberg-JS 10 ай бұрын
Decent points, indeed. (Though these functions have the complexity that hits locals -- bigger functions aren't necessarily harder in this respect.) We're currently working our way through `base` (our open-source standard library), adding local annotations throughout. It's not particularly easy! And yet the benefits we're seeing seem worth the cost. A big question we're thinking about is how this will all shake out in the end, which is one of the reasons we want to develop this on a branch of the compiler instead of pushing early for inclusion in general OCaml.
@karavanidet
@karavanidet 11 ай бұрын
I am subscribed, I have a bell - I only see this now
Stack Allocation with Locals in OCaml | OCaml Unboxed
11:07
Jane Street
Рет қаралды 1,7 М.
Unboxed Types for OCaml
47:18
Jane Street
Рет қаралды 7 М.
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.
Air Sigma Girl #sigma
0:32
Jin and Hattie
Рет қаралды 45 МЛН
The Lost World: Living Room Edition
0:46
Daniel LaBelle
Рет қаралды 27 МЛН
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
I implemented Goto in OCaml
38:41
Tsoding Daily
Рет қаралды 43 М.
Garbage Collection (Mark & Sweep) - Computerphile
16:22
Computerphile
Рет қаралды 252 М.
Uncle Bob LOVES Functional Programming | Prime Reacts
22:59
ThePrimeTime
Рет қаралды 127 М.
Garbage Collection in Python: Speed Up Your Code
16:41
NeuralNine
Рет қаралды 19 М.
How OCaml Makes Ints Speedy | Prime Reacts
20:21
ThePrimeTime
Рет қаралды 56 М.
[OCaML'23] State of the OCaml Platform 2023
22:23
ACM SIGPLAN
Рет қаралды 1,6 М.
Memory allocation in OCaml and beyond
37:02
Artem Pianykh
Рет қаралды 4,1 М.
Ocaml Becomes Rust w/ Garbage Collection?
47:31
ThePrimeTime
Рет қаралды 73 М.
Reactive Programming with Diff & Patch • Yaron Minsky • YOW! 2018
53:38
How the C++ Linker Works
15:52
The Cherno
Рет қаралды 652 М.
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.