OCaml Locals Save Allocations | OCaml Unboxed

  Рет қаралды 1,749

Jane Street

Jane Street

4 ай бұрын

This is the fifth video in a series about OCaml’s locals. This episode demonstrates how using locals reduces garbage-collected allocations. Watch as I demonstrate how to use locals, fending off plenty of error messages along the way.
View instructions to get the compiler I use in this video: github.com/janestreet/opam-re...
Code used in this video: github.com/goldfirere/janestr...

Пікірлер: 16
@alicaglayanrulzok
@alicaglayanrulzok 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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 3 ай бұрын
@@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 3 ай бұрын
@@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 Ай бұрын
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 Ай бұрын
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.
@karavanidet
@karavanidet 4 ай бұрын
I am subscribed, I have a bell - I only see this now
@a_external_ways.fully_arrays
@a_external_ways.fully_arrays 4 ай бұрын
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 4 ай бұрын
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.
@MirceaPricop
@MirceaPricop 3 ай бұрын
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 3 ай бұрын
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!
@user-lq6fx6sk4j
@user-lq6fx6sk4j 4 ай бұрын
does anybody know that colorscheme. its so clean
@RichardEisenberg-JS
@RichardEisenberg-JS 4 ай бұрын
It's One Monokai in VS Code, with a bunch (~15 lines) of customizations.
@vinylwarmth
@vinylwarmth 4 ай бұрын
@@RichardEisenberg-JScould you share please? 😁
@kozmicluis2552
@kozmicluis2552 3 ай бұрын
Looks like a custom high-contrast monokai but I use 2 similar high contrast themes that I am satisfied with: Nigh Wolf - No Italics Dark Moon
Stack Allocation with Locals in OCaml | OCaml Unboxed
11:07
Jane Street
Рет қаралды 1,4 М.
Inferring Locality in OCaml | OCaml Unboxed
22:27
Jane Street
Рет қаралды 1,2 М.
Watermelon Cat?! 🙀 #cat #cute #kitten
00:56
Stocat
Рет қаралды 43 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 7 МЛН
I’m just a kid 🥹🥰 LeoNata family #shorts
00:12
LeoNata Family
Рет қаралды 6 МЛН
Ocaml Becomes Rust w/ Garbage Collection?
47:31
ThePrimeTime
Рет қаралды 70 М.
Meet a Quantitative Researcher at SIG
2:20
Susquehanna International Group
Рет қаралды 2,1 М.
A Jane Street Trading Mock Interview with Graham and Andrea
25:43
Jane Street
Рет қаралды 238 М.
Wait, but Who's Debugging the Debugger?!
59:53
Tsoding Daily
Рет қаралды 34 М.
The Rust Standard Library is SO Confusing...Until Now!
11:45
Travis Media
Рет қаралды 23 М.
tree-sitter explained
15:00
TJ DeVries
Рет қаралды 73 М.
Arenas, strings and Scuffed Templates in C
12:28
VoxelRifts
Рет қаралды 77 М.
После ввода кода - протирайте панель
0:18
One To Three USB Convert
0:42
Edit Zone 1.8M views
Рет қаралды 441 М.
5 НЕЛЕГАЛЬНЫХ гаджетов, за которые вас посадят
0:59
Кибер Андерсон
Рет қаралды 1,6 МЛН
Мечта Каждого Геймера
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 1,6 МЛН