Let's prototype a JavaScript JIT compiler!

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 108

  • @timschumi
    @timschumi Год назад +93

    A surprise to be sure, but a welcome one.

  • @joelpetersson8742
    @joelpetersson8742 Год назад +132

    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!

    • @DavidBerglund
      @DavidBerglund Год назад

      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?

    • @kreuner11
      @kreuner11 Год назад +1

      ​@@DavidBerglundyes, a JIT compiler for a subset to gain an understanding of how it could be implemented full-time

    • @DavidBerglund
      @DavidBerglund Год назад +1

      @@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?

    • @merthyr1831
      @merthyr1831 Год назад +6

      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!

    • @eldonad
      @eldonad Год назад +5

      @@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

  • @fredleckie5880
    @fredleckie5880 Год назад +38

    The Return of the Kling!

  • @DevvOscar
    @DevvOscar Год назад +45

    This is the kind of programmer i am in my head.

  • @-lolus-
    @-lolus- Год назад +32

    he's back :D

    • @awesomekling
      @awesomekling  Год назад +12

      Well helloooooooooooo friends! :^)

  • @mariocamspam72
    @mariocamspam72 Год назад +28

    That outside view is so nice, really relaxing stuff!

  • @insanedbg
    @insanedbg Год назад +17

    Thanks for this new recording, such a pleasant surprise and a joy to watch you work your magic. You were missed ☺

  • @itskarudo
    @itskarudo Год назад +9

    actually jumped off my chair on seeing the title :))

  • @StevenHokins
    @StevenHokins Год назад +6

    New series hype? 😊 seatbelts ready for watching more videos ❤

  • @toms2oo8
    @toms2oo8 Год назад +27

    Copilot still blows my mind (when its right)

    • @awesomekling
      @awesomekling  Год назад +11

      Same, it makes programming feel so much lighter and faster once you figure out how to co-op with it!

  • @eldonad
    @eldonad Год назад +26

    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...

  • @Rice7th
    @Rice7th Год назад +10

    Finally! I was waiting for a jit compiler for a while!

    • @contextfree
      @contextfree Год назад

      Me too! Excited to see where this goes.

  • @keeslinp
    @keeslinp Год назад +2

    The cozy yak got a like from me before the "hello friends" even made it all the way out :D

  • @pierrecollignon8146
    @pierrecollignon8146 Год назад +10

    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 🛠

  • @igalshilman4062
    @igalshilman4062 Год назад +1

    Oh boy I’ve missed that “well hello friends” sweet sound

  • @jasonaskew462
    @jasonaskew462 Год назад +7

    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 =)

  • @abhishekraturi9113
    @abhishekraturi9113 Год назад +4

    its great to see you back Andreas. Your new setup looks really nice

  • @cagnolin.A
    @cagnolin.A 8 месяцев назад

    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.

  • @Bobbias
    @Bobbias Год назад +4

    Happy to see another video! Hope the move went well.

  • @yjk_ch
    @yjk_ch Год назад +4

    Copilot's guesses were already amazing in this video, but I was like "WHAT?!" when it generated code that emits x86 instructions.

  • @rouldiy
    @rouldiy Год назад +1

    The return of the Kling! Good to see you back with new and exciting RUclips content. Missed you!

  • @kolemannix8256
    @kolemannix8256 Год назад +1

    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

  • @limalimon1738
    @limalimon1738 Год назад +3

    Great video!! Very informative. Keep it up!
    Btw, I loved that wallpaper! Where can I find it?

  • @bas8036
    @bas8036 Год назад +1

    This video reminded me on your outstanding super-low-level knowledge. It blows my mind.

  • @chenhonzhou
    @chenhonzhou Год назад

    Welcome back, hope to update more videos. I want to know more about your programming ideas and your implementation ideas.🥰

  • @АлександрПогорельский-г5с

    Oh, how long I wait your long videos! Thank you so much! Great work!
    P.S. new computer loft looks perfect)

  • @Dr-Zed
    @Dr-Zed Год назад +2

    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.

  • @perotubinger
    @perotubinger Год назад +1

    I am so happy to see another video! ❤

  • @solcloud
    @solcloud Год назад +2

    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 🙂

  • @MrJakob
    @MrJakob Год назад +5

    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.

    • @awesomekling
      @awesomekling  Год назад +7

      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

  • @milanakik1539
    @milanakik1539 Год назад +5

    One hundred thousand times. *writes one hundred million*

  • @booyakahhh
    @booyakahhh Год назад +2

    Nice to have you back 😊

  • @antropod
    @antropod 7 месяцев назад

    Seeing copilot in action blew my mind

  • @Koutsie
    @Koutsie Год назад +8

    need more pics of the computer-loft :D

    • @maartenofbelgium
      @maartenofbelgium Год назад +2

      I'm curious how it's warmed and how well it is insulated. While it's not yet here, but winter is coming.

    • @kreuner11
      @kreuner11 Год назад

      ​@@maartenofbelgiuma loft suggests a partial floor above a room, so I guess the same as the house

  • @thomasziereis330
    @thomasziereis330 Год назад

    This is literally the best video i ever watched

  • @93davve93
    @93davve93 Год назад

    Great stuff, good to see you live code again!

  • @nopair5688
    @nopair5688 Год назад

    Thank you Andress😍 thank you for sharing your work. Amazing 🍰

  • @maksadbek
    @maksadbek Год назад

    Amazing work! Andreas is a king of software development

  • @wuddddd
    @wuddddd Год назад +1

    hope to be back

  • @Nunya58294
    @Nunya58294 Год назад

    Like the new setup Andreas!

  • @forayer
    @forayer 9 месяцев назад

    This video also made me rethink my approach to not using copilot anymore

  • @DanelonNicolas
    @DanelonNicolas Год назад

    Oh I have pr to check Andreas! now I'm happy to see a new video ❤ yay 😅🎉

  • @redon638
    @redon638 11 месяцев назад

    Incredible video! I am new to c++, you are using Vector and u64 and some macros, are they part of some library or framework?

  • @vongodric
    @vongodric Год назад +5

    Why not use Jakt? Is Jakt dead a project now? Haven't heard any news about it...

  • @abdelfetah
    @abdelfetah Год назад +1

    Welcome back ✌

  • @pizzapanni
    @pizzapanni Год назад

    What is the JetBrains theme you're using? This looks good!

  • @ac130kz
    @ac130kz Год назад +1

    Yay! Finally a JIT!

  • @halemm
    @halemm Год назад

    very beautiful video indeed

  • @julianriise131
    @julianriise131 11 месяцев назад

    Lovely, thanks for sharing. Can I ask which font you are using in your IDE?

  • @americo9999
    @americo9999 Месяц назад

    I miss these coding videos

  • @BenjaminAster
    @BenjaminAster Год назад +3

    Had to quickly check the date if it's not April 1st 😅

  • @mzmzgreen
    @mzmzgreen Год назад

    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.

  • @aleksandr2245
    @aleksandr2245 Год назад

    wow! Great video. Keep it up!

  • @h0rst
    @h0rst Год назад +3

    So the format of these videos has changed from “watch human write code” to “watch human watch bot write code” 😅

  • @danieloberhoff1
    @danieloberhoff1 Год назад

    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?

    • @danieloberhoff1
      @danieloberhoff1 Год назад

      ah ok, so the bytecode is the IR. I wonder can you run optimizations on the bytecode?

  • @MaximSchoemaker
    @MaximSchoemaker Год назад

    Welcome back 💖

  • @adityagujaria2598
    @adityagujaria2598 Год назад

    Hey Welcome back !!! By any chance can we see access. cpp. I just checked the serenity repo. I think it's not there.

  • @slendi9623
    @slendi9623 Год назад

    Cool stuff mate

  • @driden1987
    @driden1987 Год назад

    Hi Andreas, what resource would you recommend to learn on how to understand VM's inner workings ?

  • @paulwratt
    @paulwratt Год назад

    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)

  • @patrickpfeiler3449
    @patrickpfeiler3449 Год назад

    That Yak Wallpaper ❤❤❤
    Would it be possible to share the link from where I can download it?

  • @diegorocha2186
    @diegorocha2186 Год назад

    Are you considering record more videos on this subject? Will be nice to see you hacking libjs :^)

  • @xeliqa3921
    @xeliqa3921 Год назад

    I need to know where you got that background from!

  • @benstigsengaming
    @benstigsengaming Год назад

    Okay, now I have try out Copilot.

  • @xeschire706
    @xeschire706 Год назад

    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!

  • @ray-cpp7234
    @ray-cpp7234 Год назад +3

    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

    • @awesomekling
      @awesomekling  Год назад +4

      Sure! gist.github.com/awesomekling/e2164c5d5f37cb005f59965cdda5945a

  • @Dysiode
    @Dysiode 11 месяцев назад

    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

    • @awesomekling
      @awesomekling  11 месяцев назад

      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 :)

  • @salemyaslem9792
    @salemyaslem9792 Год назад +1

    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

  • @nunoalexandre6408
    @nunoalexandre6408 Год назад

    Love it!!!!!!!!!!!

  • @maixicek
    @maixicek Год назад +3

    yeeeeeeeeeeeeeeeeees

  • @emanuele6
    @emanuele6 Год назад +1

    30:58 using JittedFunction = void(*)(VM &); is how you do it :^)

  • @shivankkunwar9669
    @shivankkunwar9669 11 месяцев назад

    What are the prerequisites to this starting this series?

  • @DavidBerglund
    @DavidBerglund Год назад

    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?

    • @DavidBerglund
      @DavidBerglund Год назад

      No wait. Parsed with [say libjs] then compiled with a JIT compiler and then interpreted with [say libjs]?

    • @kreuner11
      @kreuner11 Год назад

      I think bytecode can be an intermediate rather than having everything implemented immediately in assembly

    • @DavidBerglund
      @DavidBerglund Год назад

      @@kreuner11 Ok, but do you think my statement above is correct?

    • @pattyspanker8955
      @pattyspanker8955 Год назад

      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 🤷‍♂️

    • @DavidBerglund
      @DavidBerglund Год назад +1

      @@pattyspanker8955Thank you! That makes sense. :)

  • @jakobpaulsson3827
    @jakobpaulsson3827 Год назад

    👑

  • @kreuner11
    @kreuner11 Год назад +1

    I'd rather be a boomer and figure out everything by myself so I actually understand it
    All boogs are my own

  • @DefinitelyNotAMachineCultist
    @DefinitelyNotAMachineCultist Год назад +10

    🎯 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

  • @jugurthagreen900
    @jugurthagreen900 9 месяцев назад

    can you optimise python3.13 ?

  • @relakin
    @relakin Год назад +1

    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?

  • @boywithacoin
    @boywithacoin 9 месяцев назад

    copy-and-patch jit!

  • @Cjw9000
    @Cjw9000 11 месяцев назад

    watching this video, i just feel stupid.

  • @fazibear
    @fazibear Год назад +4

    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?

    • @JonRonnenberg
      @JonRonnenberg Год назад

      That makes no sense. WASM still need to be compiled to machine code.. Same as JS. Only WASM is an easier input than JS