How OCaml Makes Ints Speedy | Prime Reacts

preview_player
Показать описание
Recorded live on twitch, GET IN

Written by: Vladimir Brankov

MY MAIN YT CHANNEL: Has well edited engineering videos

Discord

Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
Рекомендации по теме
Комментарии
Автор

I run into the ‘period & quotes’ problem daily. If I’m trying to indicate a programming term or variable name by enclosing it in punctuation, then I don’t want to include a period—regardless of which is correct. I would rather avoid confusion than be correct, which is rarely the case tbh

AG-urlj
Автор

"You can count your users with an 8-bit integer". Savage, lol.

Euphorya
Автор

@Prime, You really should take the time to learn assembly. It will give you so much more insight into the inner workings of computers.

X86-64 would be the obvious choice, but RISC-V would be much faster to learn. Once you fully understand one architecture, it’s easy to learn the others.

You could even make a series where you write a RISC-V assembler/emulator in Zig. That would be very helpful for the young people watching. I actually have thought about doing that for my learn Zig project, but I’m not a youtuber.

I wrote a lot of 6502 assembly in the ‘80s and even though I haven’t written much assembly since, it has helped me a lot when writing code in high level languages.

Btw. Logical Shift Left means you zero extent the result. You usually have LSL, LSR and ASR. The two latter are Logical and Arithmetic Shift Right. The Arithmetic version copies the sign bit in from the right and the Logical version copies in zeroes in the most significant bits.

NoX-
Автор

If a 32 bit integer is enough you could store a 64 bit value (the upper half being the header and the lower half being the integer) in rdx (64 bit register) and use edx (32 bit register, addresses the lower half of rdx) to do normal arithmetic on the ineger.

foxcirc
Автор

Do garbage collectors not maintain a data structure of allocated memory with types associated? So that you wouldn't have to differentiate ints and pointers by value alone?

murtaza
Автор

I haven't watched the entire video (minute 4) but this is called pointer swizzling, it surprises me that this term isn't mentioned yet

RngeRpidz
Автор

Fullstop/period inside the quote marks was apparently just to look better even though it wasn't logical. I'm not sure if it was supposed to look better mainly in typesetting, handwriting, typing, or all of them. People just memorized it as an absolute rule though with no reasoning or explanation, which made it one of those religious arguments.

andrewdunbar
Автор

I guess Java uses this stuff since ... ever. Every memory allocation is aligned to last 3 bits, meaning aligned by 8 in 64bit JVM. And aligned to at least 2bits, meaning aligned by 4 in 32bit JVM. So they could use those bits for ... stuff. For example marking the pointer as visited/not visited by garbage collector. Color in red-black tree. Distinguish pointer to boxed integer / float vs in-place integer / float as mentioned here in OCaml case. Java on 64bit OS could be configured to use 32 bit pointers, if each pointer is aligned to (lets say) 4 bits, that would give limitation of max 64 GB RAM heap, but each pointer (object reference in Java speak) would be half the size, meaning both processing speed and memory consumption optimization. Similar JavaScript in V8, they are using few lowest bits for similar shenanigans. Similar Ruby. And I guess every interpreted language. (I never looked inside Python interpreter.)

MarekKnapek
Автор

I'm not sure I understand why this is needed in Ocaml. Surely as a statically typed language (with some beautiful type inference capabilities), the compiler could know whether something is an integer or not at compile time, without any runtime checks? Like, this is why C++ doesn't need anything like this, even though it does something very similar with small string optimizations, because strings are a variably sized type and need to go on the heap.

yaksher
Автор

For optimal CPU Feng Shui you really want about 61.8034 bits.

JuusoAlasuutari
Автор

Does OCaml also use tagged pointers for sum types?

-ion
Автор

American "something." is like writing code like this:
fn american() {
f(
})

Aras
welcome to shbcf.ru