Absolutely fantastic video! I always assumed that JIT compiling was this extremely esoteric and difficult thing to build, but in classic AK fashion you managed to demystify it in under 2 hours. Truly superb work!
Between him and Tsoding there's so much stuff I've learned in great depth thanks to just watching two very intelligence engineers taking these problems head-on. bravo!
@@DavidBerglund so the idea is, a bit like it's implemented in current JIT systems like in V8, both bytecode and JIT act upon the VM, but some instructions can be optimized to machine assembly (and some not, because Js), and so you have a fast route where the ASM is executed, and a slow route for more complex operations. Also there is a huge bit of caching involved, V8 is wizardry after all
Andreas's interactions with Copilot have a very "patient senior coaching the new intern" vibe ! I started using Copilot myself not too long ago, it's really life changing in terms of productivity, but I don't know, I usually prefer my tools to be predictable, having to read something else's code continuously I find more tiring in the long term... Probably a matter of habit and tool maturity, no doubt in a few years this will be greatly improved...
This is gold for anyone jumping into engineering and problem-solving (as always), and I think you adding an extra pro-guidance on how to (and not to) use Copilot just makes your content that much more enjoyable and actionable for builders hesitating to take the jump into POCing their awesome ideas! Thanks Andreas, you truly rock 🛠
This was incredible. Thank you for sharing and now I'm hooked. Listening to your Thought process reminds me of tbe delight of reading the "zen of graphics programing" by Michael Abrash back in 1998. Please keep it up =)
Hey Andreas. I've been watching since years ago. Came back after a long break and very glad to see the change in your appearance, mood, and location! I'm very excited to catch up on the progress of everything (the browser being the most interesting to me.) Thanks for all you do.
Thanks very much for making the effort to record and post this video. Amazing introduction to JITs in general, and turned out to be a rather impressive Copilot demo! Thank you
I love using copilot to generate types by just pasting a bunch of json into a comment. It's so pleasant not having to write boilerplate code from scratch.
My favorite programmer is back with RUclips content ❤ Also new loft looks good 👍window should provide enough fresh air for recording many long hacking videos 🙂
As always a great pleasure to watch. I always wanted to take a deeper look into how JIT compilers are actually created. Always thought they are really complex from the get go. And even though I can of course see how they are quite complex in the end to handle all kinds of different scenarios, they are indeed nothing more than quite minimalistic on the fly assemblers. Never would have thought that it is so "simple" to create something like that. At least you make it look quite simple :). I really much like the wallpaper btw. it looks so peaceful any chance to get a link for that specific one? Couldn't find it by usual means. Thanks again for this and all your other videos, really much enjoying all your work.
Thanks for recording this! Can you please add links to resources you used for learning/researching a given topic under your videos when applicable? I checked the description of this video but haven't found anything.
cool, wonder how far you get with this. hmm, you kinda end up with a new ir no? i mean the assembly snippets are kind of instructions on their own right?
based on your opening statements, I am wondering if using Jakt as the basis might be worth doing, even if you patch resulting C++ output (if you can figure it out)
I still think you can have security critical systems without trading off performance at all, or at the very least not by much, there is a way to pull it off, but it does require a lot of outside the box thinking!
small request: could you please share link to the jit.cpp code? I am interested in writing my own and would like to use the structure here as reference, thanks
5:19 "just copying that in although I'm not sure why" 45 seconds later "oh, Copilot noticed all my instructions, actually" I honestly can't imagine working without Copilot anymore! Any time it's bugged out and lost connection I'll find myself staring at part of a line waiting for Copilot to fill in the blanks, it's wild how fast it happened too
Yeah I realized after posting this video that I've started pasting random context into code files to help Copilot. One of many new (initially) unconscious habits :)
you have opportunity to invent new JS compiler and Ladybird can make new solutions to give better speeds without depend on JIT or competitors solutions
Please help a confused (and amazed) individual. Would this thing (or rather a future more evolved version of this) take over after an interpreter first translated the JS code into bytecode? Could libjs be used for that step and hand it off the JIT compiler? Or am I getting it backwards?
As another confused person with no credentials, I think you're on the right track. Broadly speaking, the process would be: Parse code into abstract syntax tree → generate bytecode → interpreter executes on bytecode At the last step, portions are selectively handed off to the JIT compiler to be executed directly by the machine I can't speak to the capabilities of libjs. If that was the root of your question, then sorry, I'm no help 🤷♂️
🎯 Key Takeaways for quick navigation: 00:00 🖥️ Introduction and Setup - Introduction to the project focused on JavaScript performance. - Discusses the need to improve performance in the existing Bytecode interpreter. - Introduces the concept of prototyping a Just-In-Time (JIT) compiler. 01:22 🤔 The Complexity Spectrum of JIT Compilers - Talks about the complexity in JIT compilers and mentions existing examples like JavaScript Core. - Highlights the possibility of creating a simpler JIT compiler. - Aims to explore how much performance gain can be had from a JIT compiler. 02:19 👨💻 Setting Up the Project Files - Initiates the project by setting up files and directories. - Adds the project to cmake lists. - Describes the goal to build a standalone JIT compiler. 03:55 📝 Writing a JavaScript Test Program - Writes a simple JavaScript program to test the existing interpreter. - Measures the time taken for the existing interpreter to execute the program. 05:19 📜 Implementing Bytecode Instructions - Lays out the bytecode representation of the JavaScript program. - Discusses the use of blocks and instructions. - Utilizes Copilot to assist in writing the code efficiently. 07:21 🗃️ VM Architecture and Data Types - Explains the architecture of the Bytecode VM. - Describes how registers and locals are stored. - Defines data types to be used in the VM. 09:50 🔄 Loop Logic and Control Flow - Discusses how the loop logic is handled in bytecode. - Explains jump instructions and control flow between blocks. 12:03 🛠️ Writing a Bytecode Interpreter - Writes a simplified bytecode interpreter to run the JavaScript program. - Measures its execution time for performance comparison. 16:27 📊 Program Dump and Debugging - Implements a function to dump the state of the program. - Talks about the need for debugging capabilities. 19:48 🚀 Beginning the JIT Compilation - Introduces the initial steps for JIT compilation. - Defines the structure for JIT compilation and prepares for block-by-block compilation. 24:29 🔄 Interpreting Bytecode Instructions - Discusses how each bytecode instruction will be interpreted. - Uses a switch-case structure to handle different instruction types. 28:40 🕒 Performance Comparison and Goals - Compares the performance of the simplified interpreter to the target JIT compiler. - Sets the stage for the next steps in JIT compilation. 31:07 🛠️ Constructing the JIT Compiler - Starts building the JIT compiler with function pointer types. - Describes the run function that will execute the compiled machine code. 33:58 🏗️ JIT Compilation Logic - Discusses how the JIT compiler will loop through blocks and instructions. - Lays the groundwork for compiling each instruction into machine code. 34:16 🖥️ Abstraction Level and Initial Assembly Approach - Discussion about the level of abstraction for handling assembly code. - Introduction of `jit` assembler to load immediate values. - Mention of hardcoding x86 64 assembly as a starting point. 36:09 📝 Register Naming and VM Interactions - Deciding on naming conventions for x86 64 and other registers. - Discussion on how VM registers and locals will be accessed. - Modifying the signature of the JIT code to take registers and locals as pointers. 38:13 🤖 Utilizing Co-Pilot for Assembler Syntax - Introduction of new assembler syntax to make the implementation easier. - Exploration of different operand options and their types. - Adjustments to make the syntax compatible with C99. 42:07 🔨 Initial Compilation and Debugging - Walkthrough of the initial compilation process. - Debugging the code, particularly the `mov` operation. - Use of Co-Pilot to generate parts of the assembler code. 49:50 🔄 Implementing Various Instructions - Implementation of store, load, jump, and conditional jump instructions. - Discussion about the need for an exit instruction as an escape hatch. - Mention of potential improvements and abstractions. 53:59 🐛 Debugging and Code Optimization - Debugging issues with the generated assembly code. - Addressing the incorrect encoding of certain instructions. - Use of Co-Pilot for debugging and generating efficient code snippets. 58:06 ⏭️ Handling Forward and Backward Jumps - Discussion about the challenges of handling forward and backward jumps. - Introduction of logic to patch jumps after compiling all blocks. - Explanation of how relative offsets are calculated for jump instructions. 01:01:31 🕵️♂️ Final Debugging and Code Review - Final debugging steps and code review. - Discussion on how Co-Pilot has accelerated the development process despite minor errors. - Plan for future improvements and potential refactoring. 01:14:14 🐛 Debugging and Verification - Discusses debugging the "less than" implementation. - Runs the program to ensure it didn't crash and verifies its runtime. 01:16:12 ⏱️ Performance Comparison - Compares the performance of the JIT compiler with the interpreter. - Notes the JIT compiler is significantly faster, mentions potential for further optimizations. 01:18:11 🛠️ JIT Structure and Optimization - Talks about the structure for the JIT compiler he's interested in building. - Discusses the possibility for "fast paths" in the JIT for handling common cases efficiently. 01:19:35 🎥 Future Plans and Closing - Plans to continue prototyping the JIT compiler. - Highlights the video as a means to narrate his thought process. 01:20:16 🚀 Shoutout and Future Considerations - Gives a shoutout to Co-pilot for assisting. - Discusses the trade-offs and possibilities of implementing the JIT compiler as an option. Made with HARPA AI
Hey! I'm just thinking loud. Meybe instead of implementing yet another JS engine. Try something different. Try to make WASM a core, and make JS just one of compiled to wasm language?
A surprise to be sure, but a welcome one.
:yakmando:
Absolutely fantastic video! I always assumed that JIT compiling was this extremely esoteric and difficult thing to build, but in classic AK fashion you managed to demystify it in under 2 hours. Truly superb work!
Same here! But I'm stil a bit confused and need to ask: is what AK is coding here a JS bytecode interpreter for a subset of possible bytecode?
@@DavidBerglundyes, a JIT compiler for a subset to gain an understanding of how it could be implemented full-time
@@kreuner11 where is the line between interpreter and compiler here? Is the purpose of this to interpret JS bytecode and turn that into machine code?
Between him and Tsoding there's so much stuff I've learned in great depth thanks to just watching two very intelligence engineers taking these problems head-on. bravo!
@@DavidBerglund so the idea is, a bit like it's implemented in current JIT systems like in V8, both bytecode and JIT act upon the VM, but some instructions can be optimized to machine assembly (and some not, because Js), and so you have a fast route where the ASM is executed, and a slow route for more complex operations. Also there is a huge bit of caching involved, V8 is wizardry after all
The Return of the Kling!
This is the kind of programmer i am in my head.
he's back :D
Well helloooooooooooo friends! :^)
That outside view is so nice, really relaxing stuff!
Thanks for this new recording, such a pleasant surprise and a joy to watch you work your magic. You were missed ☺
Thank you! It's good to be back
actually jumped off my chair on seeing the title :))
New series hype? 😊 seatbelts ready for watching more videos ❤
Copilot still blows my mind (when its right)
Same, it makes programming feel so much lighter and faster once you figure out how to co-op with it!
Andreas's interactions with Copilot have a very "patient senior coaching the new intern" vibe !
I started using Copilot myself not too long ago, it's really life changing in terms of productivity, but I don't know, I usually prefer my tools to be predictable, having to read something else's code continuously I find more tiring in the long term... Probably a matter of habit and tool maturity, no doubt in a few years this will be greatly improved...
Finally! I was waiting for a jit compiler for a while!
Me too! Excited to see where this goes.
The cozy yak got a like from me before the "hello friends" even made it all the way out :D
This is gold for anyone jumping into engineering and problem-solving (as always), and I think you adding an extra pro-guidance on how to (and not to) use Copilot just makes your content that much more enjoyable and actionable for builders hesitating to take the jump into POCing their awesome ideas!
Thanks Andreas, you truly rock 🛠
Oh boy I’ve missed that “well hello friends” sweet sound
This was incredible. Thank you for sharing and now I'm hooked. Listening to your Thought process reminds me of tbe delight of reading the "zen of graphics programing" by Michael Abrash back in 1998. Please keep it up =)
its great to see you back Andreas. Your new setup looks really nice
Hey Andreas. I've been watching since years ago. Came back after a long break and very glad to see the change in your appearance, mood, and location! I'm very excited to catch up on the progress of everything (the browser being the most interesting to me.) Thanks for all you do.
Happy to see another video! Hope the move went well.
Copilot's guesses were already amazing in this video, but I was like "WHAT?!" when it generated code that emits x86 instructions.
The return of the Kling! Good to see you back with new and exciting RUclips content. Missed you!
Thanks very much for making the effort to record and post this video. Amazing introduction to JITs in general, and turned out to be a rather impressive Copilot demo! Thank you
Great video!! Very informative. Keep it up!
Btw, I loved that wallpaper! Where can I find it?
This video reminded me on your outstanding super-low-level knowledge. It blows my mind.
Welcome back, hope to update more videos. I want to know more about your programming ideas and your implementation ideas.🥰
Oh, how long I wait your long videos! Thank you so much! Great work!
P.S. new computer loft looks perfect)
I love using copilot to generate types by just pasting a bunch of json into a comment. It's so pleasant not having to write boilerplate code from scratch.
I am so happy to see another video! ❤
My favorite programmer is back with RUclips content ❤ Also new loft looks good 👍window should provide enough fresh air for recording many long hacking videos 🙂
As always a great pleasure to watch. I always wanted to take a deeper look into how JIT compilers are actually created. Always thought they are really complex from the get go. And even though I can of course see how they are quite complex in the end to handle all kinds of different scenarios, they are indeed nothing more than quite minimalistic on the fly assemblers. Never would have thought that it is so "simple" to create something like that. At least you make it look quite simple :).
I really much like the wallpaper btw. it looks so peaceful any chance to get a link for that specific one? Couldn't find it by usual means.
Thanks again for this and all your other videos, really much enjoying all your work.
Yeah, there's a huge spectrum of complexity to JIT compilation. We're starting at the bottom end here :^)
Wallpaper: i.imgur.com/TRHPrPD.png
One hundred thousand times. *writes one hundred million*
Nice to have you back 😊
Seeing copilot in action blew my mind
need more pics of the computer-loft :D
I'm curious how it's warmed and how well it is insulated. While it's not yet here, but winter is coming.
@@maartenofbelgiuma loft suggests a partial floor above a room, so I guess the same as the house
This is literally the best video i ever watched
Great stuff, good to see you live code again!
Thank you Andress😍 thank you for sharing your work. Amazing 🍰
Amazing work! Andreas is a king of software development
hope to be back
Like the new setup Andreas!
This video also made me rethink my approach to not using copilot anymore
Oh I have pr to check Andreas! now I'm happy to see a new video ❤ yay 😅🎉
Incredible video! I am new to c++, you are using Vector and u64 and some macros, are they part of some library or framework?
Why not use Jakt? Is Jakt dead a project now? Haven't heard any news about it...
Welcome back ✌
What is the JetBrains theme you're using? This looks good!
Yay! Finally a JIT!
very beautiful video indeed
Lovely, thanks for sharing. Can I ask which font you are using in your IDE?
It’s Berkeley Mono
Lovely! @@awesomekling
I miss these coding videos
Had to quickly check the date if it's not April 1st 😅
Thanks for recording this! Can you please add links to resources you used for learning/researching a given topic under your videos when applicable? I checked the description of this video but haven't found anything.
wow! Great video. Keep it up!
So the format of these videos has changed from “watch human write code” to “watch human watch bot write code” 😅
cool, wonder how far you get with this. hmm, you kinda end up with a new ir no? i mean the assembly snippets are kind of instructions on their own right?
ah ok, so the bytecode is the IR. I wonder can you run optimizations on the bytecode?
Welcome back 💖
Hey Welcome back !!! By any chance can we see access. cpp. I just checked the serenity repo. I think it's not there.
Cool stuff mate
Hi Andreas, what resource would you recommend to learn on how to understand VM's inner workings ?
based on your opening statements, I am wondering if using Jakt as the basis might be worth doing, even if you patch resulting C++ output (if you can figure it out)
That Yak Wallpaper ❤❤❤
Would it be possible to share the link from where I can download it?
Are you considering record more videos on this subject? Will be nice to see you hacking libjs :^)
I need to know where you got that background from!
Okay, now I have try out Copilot.
I still think you can have security critical systems without trading off performance at all, or at the very least not by much, there is a way to pull it off, but it does require a lot of outside the box thinking!
small request: could you please share link to the jit.cpp code? I am interested in writing my own and would like to use the structure here as reference, thanks
Sure! gist.github.com/awesomekling/e2164c5d5f37cb005f59965cdda5945a
5:19 "just copying that in although I'm not sure why" 45 seconds later "oh, Copilot noticed all my instructions, actually" I honestly can't imagine working without Copilot anymore! Any time it's bugged out and lost connection I'll find myself staring at part of a line waiting for Copilot to fill in the blanks, it's wild how fast it happened too
Yeah I realized after posting this video that I've started pasting random context into code files to help Copilot. One of many new (initially) unconscious habits :)
you have opportunity to invent new JS compiler and Ladybird can make new solutions to give better speeds without depend on JIT or competitors solutions
Love it!!!!!!!!!!!
yeeeeeeeeeeeeeeeeees
30:58 using JittedFunction = void(*)(VM &); is how you do it :^)
What are the prerequisites to this starting this series?
Please help a confused (and amazed) individual. Would this thing (or rather a future more evolved version of this) take over after an interpreter first translated the JS code into bytecode? Could libjs be used for that step and hand it off the JIT compiler? Or am I getting it backwards?
No wait. Parsed with [say libjs] then compiled with a JIT compiler and then interpreted with [say libjs]?
I think bytecode can be an intermediate rather than having everything implemented immediately in assembly
@@kreuner11 Ok, but do you think my statement above is correct?
As another confused person with no credentials, I think you're on the right track. Broadly speaking, the process would be:
Parse code into abstract syntax tree → generate bytecode → interpreter executes on bytecode
At the last step, portions are selectively handed off to the JIT compiler to be executed directly by the machine
I can't speak to the capabilities of libjs. If that was the root of your question, then sorry, I'm no help 🤷♂️
@@pattyspanker8955Thank you! That makes sense. :)
👑
I'd rather be a boomer and figure out everything by myself so I actually understand it
All boogs are my own
🎯 Key Takeaways for quick navigation:
00:00 🖥️ Introduction and Setup
- Introduction to the project focused on JavaScript performance.
- Discusses the need to improve performance in the existing Bytecode interpreter.
- Introduces the concept of prototyping a Just-In-Time (JIT) compiler.
01:22 🤔 The Complexity Spectrum of JIT Compilers
- Talks about the complexity in JIT compilers and mentions existing examples like JavaScript Core.
- Highlights the possibility of creating a simpler JIT compiler.
- Aims to explore how much performance gain can be had from a JIT compiler.
02:19 👨💻 Setting Up the Project Files
- Initiates the project by setting up files and directories.
- Adds the project to cmake lists.
- Describes the goal to build a standalone JIT compiler.
03:55 📝 Writing a JavaScript Test Program
- Writes a simple JavaScript program to test the existing interpreter.
- Measures the time taken for the existing interpreter to execute the program.
05:19 📜 Implementing Bytecode Instructions
- Lays out the bytecode representation of the JavaScript program.
- Discusses the use of blocks and instructions.
- Utilizes Copilot to assist in writing the code efficiently.
07:21 🗃️ VM Architecture and Data Types
- Explains the architecture of the Bytecode VM.
- Describes how registers and locals are stored.
- Defines data types to be used in the VM.
09:50 🔄 Loop Logic and Control Flow
- Discusses how the loop logic is handled in bytecode.
- Explains jump instructions and control flow between blocks.
12:03 🛠️ Writing a Bytecode Interpreter
- Writes a simplified bytecode interpreter to run the JavaScript program.
- Measures its execution time for performance comparison.
16:27 📊 Program Dump and Debugging
- Implements a function to dump the state of the program.
- Talks about the need for debugging capabilities.
19:48 🚀 Beginning the JIT Compilation
- Introduces the initial steps for JIT compilation.
- Defines the structure for JIT compilation and prepares for block-by-block compilation.
24:29 🔄 Interpreting Bytecode Instructions
- Discusses how each bytecode instruction will be interpreted.
- Uses a switch-case structure to handle different instruction types.
28:40 🕒 Performance Comparison and Goals
- Compares the performance of the simplified interpreter to the target JIT compiler.
- Sets the stage for the next steps in JIT compilation.
31:07 🛠️ Constructing the JIT Compiler
- Starts building the JIT compiler with function pointer types.
- Describes the run function that will execute the compiled machine code.
33:58 🏗️ JIT Compilation Logic
- Discusses how the JIT compiler will loop through blocks and instructions.
- Lays the groundwork for compiling each instruction into machine code.
34:16 🖥️ Abstraction Level and Initial Assembly Approach
- Discussion about the level of abstraction for handling assembly code.
- Introduction of `jit` assembler to load immediate values.
- Mention of hardcoding x86 64 assembly as a starting point.
36:09 📝 Register Naming and VM Interactions
- Deciding on naming conventions for x86 64 and other registers.
- Discussion on how VM registers and locals will be accessed.
- Modifying the signature of the JIT code to take registers and locals as pointers.
38:13 🤖 Utilizing Co-Pilot for Assembler Syntax
- Introduction of new assembler syntax to make the implementation easier.
- Exploration of different operand options and their types.
- Adjustments to make the syntax compatible with C99.
42:07 🔨 Initial Compilation and Debugging
- Walkthrough of the initial compilation process.
- Debugging the code, particularly the `mov` operation.
- Use of Co-Pilot to generate parts of the assembler code.
49:50 🔄 Implementing Various Instructions
- Implementation of store, load, jump, and conditional jump instructions.
- Discussion about the need for an exit instruction as an escape hatch.
- Mention of potential improvements and abstractions.
53:59 🐛 Debugging and Code Optimization
- Debugging issues with the generated assembly code.
- Addressing the incorrect encoding of certain instructions.
- Use of Co-Pilot for debugging and generating efficient code snippets.
58:06 ⏭️ Handling Forward and Backward Jumps
- Discussion about the challenges of handling forward and backward jumps.
- Introduction of logic to patch jumps after compiling all blocks.
- Explanation of how relative offsets are calculated for jump instructions.
01:01:31 🕵️♂️ Final Debugging and Code Review
- Final debugging steps and code review.
- Discussion on how Co-Pilot has accelerated the development process despite minor errors.
- Plan for future improvements and potential refactoring.
01:14:14 🐛 Debugging and Verification
- Discusses debugging the "less than" implementation.
- Runs the program to ensure it didn't crash and verifies its runtime.
01:16:12 ⏱️ Performance Comparison
- Compares the performance of the JIT compiler with the interpreter.
- Notes the JIT compiler is significantly faster, mentions potential for further optimizations.
01:18:11 🛠️ JIT Structure and Optimization
- Talks about the structure for the JIT compiler he's interested in building.
- Discusses the possibility for "fast paths" in the JIT for handling common cases efficiently.
01:19:35 🎥 Future Plans and Closing
- Plans to continue prototyping the JIT compiler.
- Highlights the video as a means to narrate his thought process.
01:20:16 🚀 Shoutout and Future Considerations
- Gives a shoutout to Co-pilot for assisting.
- Discusses the trade-offs and possibilities of implementing the JIT compiler as an option.
Made with HARPA AI
can you optimise python3.13 ?
Question, does anybody else make videos of Serenity/Ladybird? I believe JT quit YT, and I'm subscribed to Linus, but is there anyone else?
copy-and-patch jit!
watching this video, i just feel stupid.
Hey! I'm just thinking loud. Meybe instead of implementing yet another JS engine. Try something different. Try to make WASM a core, and make JS just one of compiled to wasm language?
That makes no sense. WASM still need to be compiled to machine code.. Same as JS. Only WASM is an easier input than JS