WEB WORKERS made my code over 100x faster (almost ZERO blocking time)

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

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

  • @JoshuaMorony
    @JoshuaMorony  Месяц назад +1

    I also have another video covering this stuff (and more) from a game dev perspective on my other channel if you'd like to check it out: ruclips.net/video/7BXvpUbNRno/видео.html

  • @Simon-yf7fo
    @Simon-yf7fo Месяц назад +30

    RUclips funily translated the title to Web-Mitarbeiter in german which means web coworker.

  • @nhkeers
    @nhkeers Месяц назад +5

    Would be interesting to see the effect of WASM for the generation code too, you could write the wave function collapse code in Go or Rust or similar and load the WASM, maybe even load it in the worker too

    • @enoua5222
      @enoua5222 7 дней назад +1

      I can confirm that this works fantastically! I made a chess game where the bot player is written in C++ and runs in a web worker

  • @NoName-1337
    @NoName-1337 Месяц назад +52

    Uff, yt translates everything into my native language. Horrible.

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

    Great video, very insightful, thanks!

  • @aheendwhz1
    @aheendwhz1 Месяц назад +56

    I almost didn't click on this video, because RUclips shit-translated title and description

    • @gigachad8091
      @gigachad8091 Месяц назад +17

      For me it said Web Employees 😂

    • @NoName-1337
      @NoName-1337 Месяц назад

      @@gigachad8091 true, "Web-Worker" -> "Web-Mitarbeiter". It makes no sense.

    • @Matrium0
      @Matrium0 Месяц назад +1

      Its really beyond me why Google does that and does not let you turn off this "feature"

  • @karamuto1565
    @karamuto1565 Месяц назад +1

    I also used web workers in our companies project as a request intercepter to a 3rd party application. This also provided the benefit of a cheap caching mechanism.

    • @ralusek
      @ralusek Месяц назад +3

      Sounds like a service worker

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

      @ralusek oh you got me. I totally mistake them for each other all the time

  • @FloKorp86
    @FloKorp86 Месяц назад +1

    I like the way you think!

  • @plastikbeau3695
    @plastikbeau3695 Месяц назад +2

    Why do you use DOM elements for terrain display in Phaser, doesn't it all happen in canvas?

    • @JoshuaMorony
      @JoshuaMorony  Месяц назад +1

      A canvas is still a DOM element, and even using Phaser's WebGL renderer (which I am doing) still requires accessing the WebGL rendering context via the canvas element, so at least as far as I understand there isn't a way to avoid the DOM entirely for actually rendering the game visibly to the screen.

    • @plastikbeau3695
      @plastikbeau3695 Месяц назад +1

      @@JoshuaMorony sure, you need a reference to the canvas to access it's APIs, but what do you need Angular for? Most Phaser configurations I saw used just a parent container selector - no frontend frameworks required. I think you could just pass around (client-server-client) the data for the terrain generation and leave rendering, as well as creating canvas element and maintaining context availability to Phaser. Am I missing something?

    • @JoshuaMorony
      @JoshuaMorony  Месяц назад +1

      ​@@plastikbeau3695 yes you can absolutely build with just Phaser, my primary motivator for including Angular is to have Angular handle the UI because I just don't like managing UIs in Phaser. So basically the canvas sits behind everything, and Angular can overlay a UI on top. But then there are also some other convenient things about using Angular, like I'm using Injectable services to manage events/data and it's nice to be able to use things like the web worker generator.

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

      @@JoshuaMorony I see, so it comes down to you being comfortable with Angular and forcing it into the workflow. All of the things you've mentioned are doable in Vanilla JS. I wouldn't take this route but you do you, might be educational for some.

    • @mateuszwojciechowski495
      @mateuszwojciechowski495 8 дней назад

      @@plastikbeau3695 everything is doable in Vanilla JS, you don't ever need React or Angular or other stuff. But sometimes it gets the job done quicker. I wouldn't go this route either but sometimes speed is worth more than cleaner/lighter code.

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

    Gaming with angular? That really caught my attention. How? Also what if you'd want to run your game in a node environment and not through browser? any alternatives?

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

    this kind of workers can be used for example to create a chat?

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

    Thjis is beautiful.
    Here's a question, with the sheer advances in GPU-native web browser support bluring the lines between a native mobile app or a PWA (or wrapped, don't really mind), web workers, and a TON of native support for other things - other than very few people targeting millions, is there really a benefit anymore to still doing native? This is mainly a mobile question

    • @JoshuaMorony
      @JoshuaMorony  Месяц назад +1

      For a game I think there are definitely strong benefits to going with a lower level/non-browser language, but as for general mobile apps/PWAs I've been of the opinion for a while that JS via something like Ionic/Capacitor is good for the majority of use cases

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

      ​@@JoshuaMorony Appreciate the opinion thank you very much.
      I have built a ton of Ionic stuff for firms with < 1000 users (usually employees, e.g. sales order lookup etc with some offline but not much) and started with Cordova, then Capacitor, but since then I have moved them to pure PWA for one reason. I HATE the app stores!

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

    does receiving message from worker triggers Change detection ?

  • @ranostaj-dev
    @ranostaj-dev Месяц назад

    How did you managed to use worker from library? NX says it only can be added to application?

    • @amackzie
      @amackzie 16 дней назад

      web workers are native to js

    • @amackzie
      @amackzie 16 дней назад

      check mozilla docs

  • @AbegazNap
    @AbegazNap Месяц назад +2

    ever the excellent teacher

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

    Joshua, I'd like to know if an OffscreenCanvas could have been helpful here ?

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

      I haven't experimented with it and don't know much about it, so not sure, but potentially

  • @delta4v
    @delta4v Месяц назад +3

    Web worker + Shared Array Buffer + wasm = maximum performance

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

      I haven't had the chance to use SharedArrayBuffer yet, but I have a fire spreading/heat transfer simulation mechanic in this game which is causing me some grief with performance still, I'm thinking there might be the potential here to utilise a worker/SharedArrayBuffer to improve this

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

    Hey Josh, fantastic content as always. I second other commenters, please disable translations... it aggressively translates the technical terms, making me clueless. Plus, your voice and tone are recognizable, while the translations voices destroy your video content, to say the least.

    • @JoshuaMorony
      @JoshuaMorony  Месяц назад +1

      Thanks, and you can switch to the original audio track in the settings for the video (I assume you can probably set this RUclips wide if you want to apply it to all videos by default too). It would be good if I could have the original audio track set by default but still have the audio dubs available for people who want them though.

  • @aheendwhz1
    @aheendwhz1 Месяц назад +2

    I almost did not click on this video, because RUclips shit-translated title and description

  • @zlatanonkovic2424
    @zlatanonkovic2424 Месяц назад +1

    The German translation for this video is "Web Coworkers".
    Just don't. Please. I know it's well meant but we're all software engineers. We speak English.
    If the title is translated, I won't click on the video. I won't watch the video.

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

      It's a new feature that's enabled by default, I'm not sure if I have any control over it. I can control the audio dubs, but I haven't been able to find any settings for title translations, I think this might be a user side setting.

  • @Barrybario
    @Barrybario Месяц назад +2

    It's a shame the interface for working with web workers is so basic

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

    5s in JS are 5ms in lower level languages, just saying

    • @JoshuaMorony
      @JoshuaMorony  Месяц назад +1

      I mostly went with JS with this because I'm good with it, I can leverage Angular, and I figured it would be a good way to also learn more about perf optimisation in JS/browser. But yes, this path is going to make some things harder and hopefully I don't end up regretting it. At least I'll learn something.

    • @diadetediotedio6918
      @diadetediotedio6918 Месяц назад +1

      @@JoshuaMorony
      Well, I'm not personally opposed to it, I just felt that WFC would benefit from a more performant language. I think you can even leverage wasm to do the heavy lifting and use JS for the core game logic, it is an interesting idea, don't you think?
      Also, talking about web frameworks, I'm personally curious, what is your opinion on solid-js, have you used it before? I recently used it and I felt it resonates with me more than angular, so I think your personal view on the enjoyability of it would be interesting

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

      ​@@diadetediotedio6918 yes I absolutely agree, but also these are the sorts of awkward situations I kind of wanted to get myself into to see how I could solve it with JS (and yes wasm is absolutely something I want to look into)
      I've never used SolidJS, but I have followed its development somewhat, and if I were to pick a framework solely based on how closely it aligns to how I think about coding/app dev it would probably end up being either SolidJS or CycleJS

    • @inlandish
      @inlandish Месяц назад +1

      That's not entirely true. Look at benchmarks and you will see JS is quite performant.

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

      ​@@inlandish
      Benchmarks are always half of the story in this sense, but I never denied JS is performant (it is not performant). The question for me is that JS is not performant in tasks that don't involve allocating huge amounts of wasted memory and in compute heavy algorithms like WFC, most benchmarks in which JS is performant against other languages really just show that JS is running on a very good JIT and GC and the other languages are not. And in most of those benchmarks JavaScript is usually from 5-30x times slower than lower level languages most of the time consistently when we talk about compute-heavy algorithms.