Squeezing Max Performance out of JavaScript

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • Streamed Live on Twitch: / tsoding
    Enable Subtitles for Twitch Chat
    More Episodes: • Raycasting in TypeScript
    References:
    - github.com/tsoding/raycasting
    - tsoding.github.io/raycasting/
    Support:
    - BTC: bc1qj820dmeazpeq5pjn89mlh9lhws7ghs9v34x9v9
    - Pay for my VPS: zap-hosting.com/en/shop/donat...
  • Věda a technologie

Komentáře • 78

  • @diegorocha2186
    @diegorocha2186 Před 14 dny +20

    Your laptop is dying, your mouse is dying, your earphones is dying, are you ok a Mr. a Zozin?

  • @lucyper8921
    @lucyper8921 Před 15 dny +78

    Mista Azozing

  • @nevokrien95
    @nevokrien95 Před 15 dny +21

    "At the time.of implementing I didn't really know any better." Story of my life.😂😂😂

  • @veevee23
    @veevee23 Před 15 dny +49

    Despite my hatred of JavaScript, I must admit that your content is very enjoyable.

    • @BboyKeny
      @BboyKeny Před 15 dny +26

      Maybe it helps that his programming style is very much like his C style. Nevertheless it may prove his point that language ≠ programming.

    • @TheSaintsVEVO
      @TheSaintsVEVO Před 14 dny +1

      How cool

    • @psteven5
      @psteven5 Před 14 dny +6

      If you’re a newer viewer. Rest assured, as his content is mostly C programming

    • @veevee23
      @veevee23 Před 13 dny +1

      @@psteven5 thank you friend. By the way, I am not new viewer. I love his every video. I don’t watch his streams but I always watch his CZcams video.

  • @CziffraNum
    @CziffraNum Před 15 dny +71

    Can someone give this man a new computer?

    • @yes-ni1od
      @yes-ni1od Před 14 dny +55

      No. If we gave everyone new computers we end up with more electron apps

    • @diegoestrada35
      @diegoestrada35 Před 13 dny +8

      abundance is the killer of art

    • @user-vt4xi5wq6v
      @user-vt4xi5wq6v Před 11 dny +3

      I think he enjoys having a slow computer

    • @LMusicTW
      @LMusicTW Před 7 dny +1

      @@yes-ni1odBased

  • @mire6134
    @mire6134 Před 15 dny +16

    Rawdogging a 2D canvas in Javascript is crazy

  • @krellin
    @krellin Před 15 dny +14

    at least your porn folder is bigger than storage on their m1 macs :D

  • @rupen42
    @rupen42 Před 14 dny +4

    Wow, you mentioned multiplayer and now I realized I'd love to see your take on websockets and p2p netcode. Simple, just the basics, no big external libraries...

  • @trg
    @trg Před 14 dny

    Great session. How about implementing spatial audio with Web Audio API?

  • @Eloii_Xia
    @Eloii_Xia Před 15 dny

    Do you think it's possible to use 3D models instead of 2D images? For example, replacing your wall image with a 3D wall without WebGL/WebGPU?

  • @monke5100
    @monke5100 Před 15 dny

    By the way, have you seen Bisqwit's video on Doom-style 3d engine in C?

  • @cheebadigga4092
    @cheebadigga4092 Před 14 dny +1

    Apparently there's a "Limit Capture Framerate" setting in OBS. Maybe it hurts your performance if it's turned on. But then again I have no idea what will happen to your streaming framerate or a/v sync if you turned it off xD

  • @zmeta8
    @zmeta8 Před 15 dny +3

    the coding style in Cesium js

  • @mykytasmirnov220
    @mykytasmirnov220 Před 15 dny +6

    Why not just memoization or using WeakSet or WeakMap for vector caching?

    • @AaronArney
      @AaronArney Před 15 dny

      That's what I was thinking too

    • @BRO-sr1vj
      @BRO-sr1vj Před 14 dny +4

      both set and map use hashing which is pretty slow

    • @Seedwreck
      @Seedwreck Před 14 dny

      @@mykytasmirnov220 I don't think he has any experience in many of the JS APIs that come bundled on both ends.

    • @AaronArney
      @AaronArney Před 14 dny

      @@BRO-sr1vj ah, good point

  • @mikejohneviota9293
    @mikejohneviota9293 Před 5 dny

    this dude is insane🎉

  • @khyernet
    @khyernet Před 14 dny +1

    this runs at consistent 144 fps on my computer. holy fuck this is amazing

  • @ivanjermakov
    @ivanjermakov Před 15 dny +9

    1:10 I'm pretty sure both Chrome and FF use hardware acceleration for their 2D canvas API.

    • @TsodingDaily
      @TsodingDaily  Před 15 dny +29

      The way we render the scene makes it irrelevant actually. We render pixel by pixel into a separate ImageData and then just slap that ImageData onto the 2D canvas. Sure the "slap" part is probably hardware accelerated, but the rest of the 90% of the work is not.

    • @ivanjermakov
      @ivanjermakov Před 15 dny +2

      @@TsodingDaily I guess the slow part is actually assembling buffer pixel by pixel, not actual rendering

    • @TsodingDaily
      @TsodingDaily  Před 15 dny +21

      Depends on whether you want to call it "rendering" or not. I personally do not see any problems in calling this process "rendering" because literally the same process of raycasting and assembling pixels was called "rendering" in the past. I don't see any reasons to not use the same word today for the same process but in a modern browser.

    • @Seedwreck
      @Seedwreck Před 14 dny

      @@ivanjermakovyeah, it is a problem that is will increase to become slower the bigger the user resolution is. Since each width of pixels makes a new bar of height pixels. Not sure if he has it capped in this case
      I don't believe he's implemented an algorithm for drawing pixels keeping unchanged yet

  • @blastygamez
    @blastygamez Před 15 dny +1

    Request for next video topic?: Squirrel programming language

  • @monke5100
    @monke5100 Před 15 dny

    My man saying "it's not hardware accelerated" like it's not already obvious lmao! Jk bruv, love you ❤

  • @karljoyeux8845
    @karljoyeux8845 Před 15 dny

    your game si amazing I am impressed by your skill

  • @mattanimation
    @mattanimation Před 15 dny

    next up, radiance cascades?

  • @debooger
    @debooger Před 15 dny +7

    ow ma gaaawd, even though they are pool allocated youre creating so much garbage in the pool itself haha, for example allocating in loops even though the object will die before next iteration. smh my head azozin

    • @debooger
      @debooger Před 14 dny

      also just a thought i had, doing it this way may negatively affect jit compiler's liveness analysis

  • @StevenMartinGuitar
    @StevenMartinGuitar Před 13 dny +1

    1:22:03 I love how you run from the bomb out of instinct before it explodes 😂 There's no damage brah, you didn't implement that yet 😊

  • @FDominicus
    @FDominicus Před 14 dny

    Don't you like to do some Pharo Smalltalk programming sometime?

  • @naranyala_dev
    @naranyala_dev Před 14 dny

    let's eat ram like chrome does

  • @scarlatum
    @scarlatum Před 14 dny

    На ещё один шаг ближе к ECS

  • @alexandrucomanescu9857
    @alexandrucomanescu9857 Před 15 dny +1

    Would it be faster to “render” the whole screen in Node.js, then stream it in the browser and display it? I’m thinking of Electron style ipc.

    • @miran248
      @miran248 Před 15 dny

      At that point you could just do it in c :)

    • @hotharvey2
      @hotharvey2 Před 15 dny

      probably, but he is aiming to keep the project simple :)

    • @lengors7327
      @lengors7327 Před 14 dny +3

      I doubt it. Why would nodejs be faster?

    • @alexandrucomanescu9857
      @alexandrucomanescu9857 Před 14 dny

      @@lengors7327 in theory you could write an entire rendering system in TS in Node.js, an environment that doesn't include the entire browser functions, then use IPC to stream rendered output in a WebGPU buffer that will render the pixels in a canvas. By doing so, you are using the same engine for all browser, meaning that you get the same performance. You could even add shaders which could increase a lot the rendering performance.

  • @Eloii_Xia
    @Eloii_Xia Před 15 dny +1

    Run at 360 FPS on my pc ^^ btw this project is really interesting !

  • @cameonn
    @cameonn Před 15 dny +1

    I thought you were going to optimize this game since the fps count was low.(While streaming) I quickly opened the end of the video and saw '20 fps' part again... Turns out it was your hardware.
    Okay. I've just watched the whole video and you mentioned FPS counter is not working correctly or not giving real numbers it supposed to give. I think the way you calculate FPS is correct, but I dunno where do you think you found a flaw for it.
    I tried opening the game in my machine and it works fantastically well for me.
    Thank you for the videos you make, it was interesting seeing profiler used on a pure js game.

  • @neverix_3600
    @neverix_3600 Před 2 dny

    could the GPU data bus be the bottleneck maybe?

  • @AndrieMC
    @AndrieMC Před 14 dny

    Make your own os (or you can't do that?)

  • @CrazyWinner357
    @CrazyWinner357 Před 14 dny +1

    Garbage collector is the worst idea ever. It's slow, complicated, unpredictable and doesn't even prevent most of the memory leaks. It creates more problems than it solves

    • @Rubyd777
      @Rubyd777 Před 7 dny

      Thats problem of developers that they dont handle async operation properly,
      How do you expect language to be easy as well as fast at the same time?

    • @CrazyWinner357
      @CrazyWinner357 Před 7 dny

      @@Rubyd777 reference counting?

  • @opsrcode
    @opsrcode Před 14 dny

    pool version 2

  • @glych002
    @glych002 Před 12 dny +2

    Best way to get max performance from JS is to not use it.

  • @antonpieper
    @antonpieper Před 15 dny +3

    Malloc in JavaScript? Memory leaks?

  • @Seedwreck
    @Seedwreck Před 15 dny +7

    Oh man, using `Object.assign(Object.create(Object.getPrototypeOf(init)), pool.init)` to create clones is very wrong.
    This just gets the prototype, makes a new object of the static prototype, and then assigns to the prototype, which means it assigns to the prototype of Object, which would be global if not a funct construct.
    Very bad.
    Should be using `Object.assign(new Reflect.getPrototypeOf(init), pool.init)` for use-case.

    • @Seedwreck
      @Seedwreck Před 15 dny +6

      Also, the game could be dramatically improved by switching to DeltaTime paradigm, just counting time since last frame to run game instead.

    • @miko007
      @miko007 Před 15 dny

      @@Seedwreckno idea what you really mean by that, but you can not just `while(true)` in the browser.

    • @Seedwreck
      @Seedwreck Před 14 dny

      @@miko007???
      Who told you this loool, and why does it matter??
      I can assure you while true does work, but you need to break the loop or it probably will crash. Still works just fine properly used
      Not sure how that relates to Reflect API but you do you

    • @miko007
      @miko007 Před 14 dny

      @@Seedwreck the browser told me this. a "forever loop" will hang the render process and the browser will abort the script after about 30 seconds.

    • @diegorocha2186
      @diegorocha2186 Před 14 dny

      I don't understand what you talking about, isn't Object.getPrototypeOf and Reflect.getPrototypeOf basically the same 'The only difference with Object.getPrototypeOf() is how non-object targets are handled.'? And how are you using 'new' with Reflect.getPrototypeOf? TypeError: Reflect.getPrototypeOf is not a constructor. I'm not that experienced with JS though!

  • @epsilonnought2648
    @epsilonnought2648 Před 11 dny

    Someone get this guy a new Meteor Lake Laptop 💻

  • @tinutom810
    @tinutom810 Před 15 dny +1

    1st

  • @AEF23C20
    @AEF23C20 Před 15 dny

    а теперь откопайте старый ie, там директ-икс напрямую браузером поддерживается, но естественно через майкрософтовский active-x и фильтры, и не парьте мозги, в ie всё работало 20 лет назад без никому не нужных свистопирделок типа бесполезных блазоров и прочей нынешней глючной забагованной тормозной трышнины

    • @AEF23C20
      @AEF23C20 Před 15 dny +1

      для тех кто не понял, всё что сделано зозиным - ранее делалось в 150 строчек кода, но через active-x и фильтры, и работало оно на древних видеокартах (200мгц 64озу) и древних процах (1ггц, 128озу) и запросто выдавало мноооого фпс-ов, оно же работало напрямую на директ-иксе, это вменяемый майкрософт который смог, а вы - нет

    • @doodocina
      @doodocina Před 15 dny

      ⁠@@AEF23C20и единственная страница, которая все это поддерживала - справочник 😂😂😂

    • @scarlatum
      @scarlatum Před 14 dny

      Ну-у-у, ты сейчас в целом можешь и WebGPU использовать, который по факту является прослойкой над Metal\Vulkan\DirectX. API в целом хорошее и не нагруженное, по крайней мере, оно приятней чем OpenGL... Ну а блейзер, да, рак тот ещё как не посуди, который ещё и свой рантайм тащит