JavaScript counters the hard way - HTTP 203

  Рет қаралды 42,347

Chrome for Developers

Chrome for Developers

Күн бұрын

Пікірлер: 179
@ChromeDevs
@ChromeDevs 3 жыл бұрын
Hey, you cared enough to scroll down to the comments! At this point you might as well subscribe.
@TheRealCAPerry
@TheRealCAPerry 3 жыл бұрын
How d'you think I got here?
@ColinRichardson
@ColinRichardson 3 жыл бұрын
@spYro double subscribe! I hear you need to SMASH the button
@PlasticCant
@PlasticCant 3 жыл бұрын
Yeah, we're going to need an else clause. We programmers generally spend much time with interpreters and compilers and are therefore fastidious.
@ajhalili2006
@ajhalili2006 3 жыл бұрын
My KZbin recommendations sent me here, even the algorithms looks broken for some people.
@Stoney_Eagle
@Stoney_Eagle 3 жыл бұрын
THE perfect way to use the pinned comment!
@Netrole
@Netrole 3 жыл бұрын
This is the only channel, where a seasoned javascript developer can still learn something in a basic counter tutorial. Very well done, and so incredibly informative.
@jakearchibald
@jakearchibald 3 жыл бұрын
Thank you! Glad it's interesting & useful
@cintron3d
@cintron3d 3 жыл бұрын
Taking simple things and making them complicated - exactly why I'm here. I don't just want to get stuff done. I want to get it done right, and understand why it's right 👍 Kudos for making such excellent content!
@sjorsborsoborsobors
@sjorsborsoborsobors 3 жыл бұрын
If I ever get asked to implement a counter during a job interview I'm hitting them with this bad boy.
@rasulturganov3421
@rasulturganov3421 3 жыл бұрын
🤣🤣🤣🤣
@abdulhadilababidi5465
@abdulhadilababidi5465 2 жыл бұрын
😂😂😂😂😂
@NateLevin
@NateLevin 3 жыл бұрын
You might not be getting the billions of views, but the videos you do make are always great!
@TheNewton
@TheNewton 3 жыл бұрын
Though work like this does end up *affecting* billions of views of webpages when it becomes standard in libraries, Frameworks and tutorials.
@mathisbullinger45
@mathisbullinger45 3 жыл бұрын
Thanks for complicating. Without it, I wouldn't have known about CSS steps() function being a thing.
@MaxArt2501
@MaxArt2501 3 жыл бұрын
Fun fact: you can clear a setInterval using clearTimeout. Because, as Surma said, setInterval is literally setTimeout that schedules itself.
@albertodeagostini6143
@albertodeagostini6143 3 жыл бұрын
This is the hardest thing to do with a seemingly simple task I've ever seen, congratulations. I loved it
@dougrudolph5400
@dougrudolph5400 3 жыл бұрын
although not pulling in millions of views, these videos are gold for the more experienced developer that wants still wants to learn something new. and the teaching style is great. it never feels like im learning, rather im discovering a topic with the both of you
@franciscoeduardo5969
@franciscoeduardo5969 2 жыл бұрын
Gracias
@akshitkrnagpal
@akshitkrnagpal 3 жыл бұрын
Now I know how should I build a counter. Thank you.
@vitabramov89
@vitabramov89 3 жыл бұрын
Making simple things hard - is the best of this channel)) because it is our frontend life, here is absolutely no simple things, but LOTS of details!
@thepaintedsock
@thepaintedsock 2 жыл бұрын
Excellent, thorough assessment of problems implementing time accuracy for js animation
@InPlainEnglishHQ
@InPlainEnglishHQ 3 жыл бұрын
Great video, thoroughly enjoy these scenic-route explanations.
@mekelius
@mekelius 2 жыл бұрын
I ran into these issues and had to figure them out while I was making a drum machine. Wish I'd had this video to hand back then :D. Even if your eyes would never detect the drift you can definitely hear it, especially when it's inconsistent.
@stenalpjolly
@stenalpjolly 3 жыл бұрын
@Jake Archibald, Great episode. Thank you so much for making things complicated ;). Please make a video on how you debug things behind the scene. How do you approach this kind of issue. I think everyone wants to see the pain went behind the scene as well.
@childishalbino9548
@childishalbino9548 3 жыл бұрын
That intro segment is exactly why I watch these videos XD
@PeerReynders
@PeerReynders 3 жыл бұрын
11:54 Nitpick: Technically the `%` operator is the "remainder" operator - not *modulo* tc39.es/ecma262/#sec-numeric-types-number-remainder The _remainder_ operator calculates the remainder of division rounded towards *zero*, i.e.: dividend - divisor * Math.trunc(dividend / divisor); _modulo_ calculates the remainder of division rounded towards *negative infinity*, i.e.: dividend - divisor * Math.floor(dividend / divisor) Both produce identical results when both operands have the same sign but produce different results when the operands have different signs. const modulo = (dividend, divisor) => ((dividend % divisor) + divisor) % divisor; const tests = [ { dividend: 5, divisor: 3, mod: 2, rem: 2 }, { dividend: 5, divisor: -3, mod: -1, rem: 2 }, { dividend: -5, divisor: 3, mod: 1, rem: -2 }, { dividend: -5, divisor: -3, mod: -2, rem: -2 }, ]; for (const { dividend, divisor, mod, rem } of tests) { console.assert( dividend % divisor === rem, `${dividend} % ${divisor} is not ${rem}` ); console.assert( modulo(dividend, divisor) === mod, `${dividend} mod ${divisor} is not ${mod}` ); } So in this use case it doesn't matter but when you're doing "clock arithmetic" you want *modulo*, not remainder.
@orlovsskibet
@orlovsskibet 3 жыл бұрын
You guys are great presenters, and provide tremendous value with your videos. Big thank you
@kingsleyoji649
@kingsleyoji649 3 жыл бұрын
Thank you for this!
@rkgkjr
@rkgkjr 3 жыл бұрын
This is super helpful for me! I've been working on a web player for a proprietary bitmap animation format from a Nintendo DS app, and getting the frames to render at the right interval has been a really annoying challenge for me. Gonna give this a whirl!
@juliohintze595
@juliohintze595 3 жыл бұрын
Beginners tutorial: how to build a counter Advanced tutorial: how to (not?) build a counter
@vhoyer
@vhoyer 3 жыл бұрын
Oh danm, I got to know this program last epsode, but I'm confident in saying that's one of the best shows/video series I've seen in a long while. Better than the shows I've been watching on netflix, but probably that on my poor ability to choose series ahha
@okletsdoitt
@okletsdoitt 3 жыл бұрын
My favorite KZbin channel! Love you guys
@rasulturganov3421
@rasulturganov3421 3 жыл бұрын
Great episode. Enjoyed watching
@Pfoffie
@Pfoffie 3 жыл бұрын
I actually really loved this. Where to learn complex stuff better than in simple problems. Also: never heard of steps in CSS before, thanks for that, too :)
@wmhilton-old
@wmhilton-old 3 жыл бұрын
Well done! Another mind-blowing episode
@tuomospx
@tuomospx 3 жыл бұрын
My usual 10 min morning coffee got extended to 24:08. Riveting geekery 👍
@KevinSheppard
@KevinSheppard 3 жыл бұрын
I learned so much about document.timeline. thanks for the complication!
@Abhishek-dp5tc
@Abhishek-dp5tc 3 жыл бұрын
Hey Jake Please put more time in explaining what code is written, would be more helpful then Loved the video, thanks
@Vladhin
@Vladhin 3 жыл бұрын
Good work digging there and SAVE CPU WHENEVER YOU CAN!
@AndreiNedelus
@AndreiNedelus 3 жыл бұрын
Hey, thanks for the explanation, I never know about document timeline :)
@karlheinzneugebauer
@karlheinzneugebauer 3 жыл бұрын
I always enjoy your tinkering videos!
@mustang19ms
@mustang19ms 3 жыл бұрын
This is gold
@shamsartem
@shamsartem 3 жыл бұрын
this was just amazing. Thank you guys
@nedeljkom
@nedeljkom 3 жыл бұрын
Very clever solution with targetNext.
@TheNewton
@TheNewton 3 жыл бұрын
Thank you for doing the deep work
@DisfigurmentOfUs
@DisfigurmentOfUs 2 жыл бұрын
Great episode, thanks! One thing that I think is wrong in the last solution is that it does not account for some browsers (safari) rounding performance.now() so it can actually be smaller than requestAnimationFrame argument. So the scheduling is not great, but rounding will take care of this.
@Manivelarino
@Manivelarino 3 жыл бұрын
I like this video concept.
@mayo2001
@mayo2001 3 жыл бұрын
I was wrapping my head around where time arg comes from. It turns out it's passed by raf - "passed a single argument, a DOMHighResTimeStamp, which indicates the current time"
@nataliaromankevich2351
@nataliaromankevich2351 3 жыл бұрын
Love this one!!
@sajankhandelwal8570
@sajankhandelwal8570 3 жыл бұрын
Thanks for the great videos..
@AndreLaBranche
@AndreLaBranche 3 жыл бұрын
Very nice job. These two perspectives are just super useful in this context, and I hope it appeals to ‘the kids’ too :)
@thekwoka4707
@thekwoka4707 2 жыл бұрын
The requestAnimationFrame example could be improved...the animation frame callback gets a timestamp given to it, so you can use that in place of date.now()
@mokkamokka4097
@mokkamokka4097 3 жыл бұрын
love ya guys!
@dwighthouse
@dwighthouse 3 жыл бұрын
Well done.
@nenadvicentic
@nenadvicentic 3 жыл бұрын
This was BRILLIANT! :)
@kezzu5849
@kezzu5849 2 жыл бұрын
Fascinating!
@EdigleyssonSilva
@EdigleyssonSilva 3 жыл бұрын
Thank you for this rich content!
@mathisbullinger45
@mathisbullinger45 3 жыл бұрын
What did you mean by the "double wrath"? (16:23)
@jakearchibald
@jakearchibald 3 жыл бұрын
It's "double raf", as in call requestAnimationFrame within requestAnimationFrame
@pulga961
@pulga961 3 жыл бұрын
requestAnimationFrame(()=>{ requestAnimationFrame(callback) } )
@paulamicel
@paulamicel 3 жыл бұрын
❤️🤓 thank you guys, this is premium web-nerd food 🍱
@NitinPasumarthy
@NitinPasumarthy 3 жыл бұрын
Wow! Excellent interview question. So many gotchas. I liked the way you presented the drift. Thanks for teaching us something new. How did you benchmark the CPU usage for each approach though? Is fair to say high CPU usage => high main thread usage for rAF, body.animate and CSS keyframes approaches?
@jakearchibald
@jakearchibald 3 жыл бұрын
I just watched the task manager to measure the CPU. Not very scientific, but the difference was extreme enough to see.
@NitinPasumarthy
@NitinPasumarthy 3 жыл бұрын
@@jakearchibald Got ya. Is fair to say high CPU usage => high main thread usage for rAF, body.animate and CSS keyframes approaches? Just trying to understand why higher CPU usage is bad if it doesn't block the main thread
@jakearchibald
@jakearchibald 3 жыл бұрын
@@NitinPasumarthy even off the main thread, CPU usage uses battery
@NitinPasumarthy
@NitinPasumarthy 3 жыл бұрын
@@jakearchibald Totally makes sense. Thank you. In general, which of rAF, body.animate and CSS keyframes approaches you shared, block the main thread and potentially impact user experience when used in other complex counters? Say, in my case, CPU & battery are less of a problem, than interactivity.
@31redorange08
@31redorange08 3 жыл бұрын
@@jakearchibald It's visible in the task manager? I was sure the difference would be too small to show up.
@trivender007
@trivender007 3 жыл бұрын
Interesting!
@AlvarLagerlof
@AlvarLagerlof 3 жыл бұрын
Amazing!
@Artea37
@Artea37 2 жыл бұрын
so great thanks
@herokenzan2231
@herokenzan2231 2 жыл бұрын
Thank you
@Abhishek-dp5tc
@Abhishek-dp5tc 3 жыл бұрын
Why would anyone dislike it
@drd2093
@drd2093 2 жыл бұрын
I literally hate Chrome timing. Implementing JSMoo, a currently 4-system emulator, getting timing to happen in any consistent way is a serious challenge.
@benlu
@benlu 3 жыл бұрын
Lol I used to do the basic thing of checking the difference of setTimeouts and the date time and calling it a day. Then I started using millisecond level clocks and stopped caring :D
@DanBlackStreams
@DanBlackStreams 3 жыл бұрын
As a developer who has written a lot of css animations... I can confirm they're pretty wonky.
@sidbits
@sidbits 3 жыл бұрын
Just curious...what earphones are you guys using? ...and microphones
@Ostap1974
@Ostap1974 3 жыл бұрын
What is your recommendation to handle longer timeouts that would be handled well over computer sleep? As an example, one minute timeout/interval to show time (hours and minutes) does not work very well over sleep.
@gregfletcher2360
@gregfletcher2360 3 жыл бұрын
This should be the video that auto plays after every js counter tutorial.
@FelipeFrancisco8
@FelipeFrancisco8 3 жыл бұрын
This is exactly why I stay away from the front-end
@cybersecurity3523
@cybersecurity3523 3 жыл бұрын
Thats good job google
@arpitdubey870
@arpitdubey870 3 жыл бұрын
I like complicated stuff. So thanks. :)
@ciberman
@ciberman 3 жыл бұрын
Since you are talking about animation, It would be interesting if you explain how requestAnimationFrame can be used with canvas in an worker thread.
@jakearchibald
@jakearchibald 3 жыл бұрын
Although we don't have an episode about this, there's developers.google.com/web/updates/2018/08/offscreen-canvas
@dassurma
@dassurma 3 жыл бұрын
Browsers that have OffscreenCanvas also have requestAnimationFrame in a Worker context
@ciberman
@ciberman 3 жыл бұрын
@@dassurma Interesting. Is that available in all major browsers? Last time I experimented with multi thread webGL rendering was a few years ago and offscreen canvas was still experimental
@wezelkrozum
@wezelkrozum 3 жыл бұрын
But what if we schedule the frame function in the video.requestVideoFrameCallback method on a looped, 1 frame per second and 1x1 resolution video?
@jakearchibald
@jakearchibald 3 жыл бұрын
Ohhhhh that's a great idea!
@jakearchibald
@jakearchibald 3 жыл бұрын
(I mean, it might be a terrible idea for all sorts of reasons, but I like your thinking)
@wezelkrozum
@wezelkrozum 3 жыл бұрын
Ah, it seems to suffer from drifting (~10ms per frame). But I'm not sure if the video framerate is precisely 1fps or if chrome does not render it precisely at 1fps. codepen.io/wesselkroos/pen/MWbjypz Also, with a ogv video the videoFrameCallback is only called once per ~11 frames...
@jakearchibald
@jakearchibald 3 жыл бұрын
@@wezelkrozum ah well, thanks for giving it a go
@tristanfraipont3782
@tristanfraipont3782 3 жыл бұрын
Regarding Chrome's rAF bug I did open crbug.com/1018120 you might want to check. Also, an other mean to have a timer is to use the Web Audio API and its AudioScheduledSourceNode. These won't tick the "Avoids running in background" case, but on the contrary they'll prevent the browser from throttling the tab's timers at all. So not great for the trees, though I didn't measure overall CPU usage, but in some cases (e.g stackoverflow.com/questions/40687010/40691112#40691112 ), we want our code to run no matter what.
@Martin-4D
@Martin-4D 3 жыл бұрын
Count efficiently!!!
@Manivelarino
@Manivelarino 3 жыл бұрын
Surprised safari is the one to have those optimizations. I just wish they also kept up with implementing new js/css features 😅
@TheNewton
@TheNewton 3 жыл бұрын
Animations are one of apples jam
@KevinFarrugia
@KevinFarrugia 3 жыл бұрын
Time to refactor all my timers!
@bkrazor3
@bkrazor3 3 жыл бұрын
Can you send us the article of Paul Luis who says setinterval is bad. I want to see what he uses instead. We want to redo all of our timers in the app as it’s causing too much of a slowdown for other things
@jakearchibald
@jakearchibald 3 жыл бұрын
If you need to run something every frame, use requestAnimationFrame. If it's a low-frequency animation, use the solution in this video. If you're using timers for other things, consider using something else developer.chrome.com/blog/timer-throttling-in-chrome-88/ 😀
@bkrazor3
@bkrazor3 3 жыл бұрын
@@jakearchibald thank you so much. I’ll start looking into all of these!
@HolarMusic
@HolarMusic 3 жыл бұрын
What about a simple requestAnimationFrame loop where you floor the time every time, but only update the UI if it's floored value changed?
@jakearchibald
@jakearchibald 3 жыл бұрын
That still performs badly (similar to the web animation example). It's the 60hz timer that uses most of the CPU, not the DOM update.
@HolarMusic
@HolarMusic 3 жыл бұрын
@@jakearchibald Interesting
@솜브레로-i8w
@솜브레로-i8w 3 жыл бұрын
Thanks!!!!
@markbailey2729
@markbailey2729 3 жыл бұрын
No other series on web development will make you so sad to be a web developer. Guaranteed!
@jakearchibald
@jakearchibald 3 жыл бұрын
Might make some "HTTP 203: bringing the sadness" t-shirts
@markbailey2729
@markbailey2729 3 жыл бұрын
@@jakearchibald Maybe it says something about me that I make sure to watch every episode you guys make. Keep up the good fight!
@SimonBuchanNz
@SimonBuchanNz 3 жыл бұрын
In "real" schedulers you generally have both a "run after/delay by" function and a "run at/delay until" function. Does JS / DOM need the latter? There's still a teeny inaccuracy between the now when you call setTimeout and when it actually executes, which might be important to someone, I guess.
@jakearchibald
@jakearchibald 3 жыл бұрын
Feels like the web animation API should be the way to do the more accurate timing, right?
@SimonBuchanNz
@SimonBuchanNz 3 жыл бұрын
@@jakearchibald call me a weirdo for thinking web animation should be for animations! More seriously I would be suspicious about it not running my code if it didn't feel like it, (background) etc., but I suppose that's all spec-able.
@jakearchibald
@jakearchibald 3 жыл бұрын
@@SimonBuchanNz ahh yeah, if you want it to run in the background, that's different. Generally we're trying to cut down on pages running stuff in the background, and instead looking at features that eg show a notification at a particular time
@SimonBuchanNz
@SimonBuchanNz 3 жыл бұрын
@@jakearchibald thinking of valid use cases is pretty tricky, to be fair: keeping a server synchronised, polling input, computing processing/usage statistics over time, but most of those are either not that time sensitive or should be parametrized by the time that's passed. I'm mostly just anxious about apis that imply a missing feature.
@TheRealCAPerry
@TheRealCAPerry 3 жыл бұрын
I just need to know what the in-ear monitors you're both using are...
@jakearchibald
@jakearchibald 3 жыл бұрын
Mine are Jabra 75t, Sumra's are Shures. IMO the Shures produce better sound & isolation, and it's what I used to use when commuting, but I find the Jabras easier to put in & take out, so they're better for calls.
@GottZ
@GottZ 3 жыл бұрын
currentTime seems nice. I used to combine the elapsed time calculated with Date.now in setTimeout with requestAnimationFrame and tried to hit the next true second elapsing. So far this works perfectly fine for me and doesn't show any drift. Now I would wonder what happens if NTP syncs time throughout the timer running.. I remember that double hit with setTimeout and I also remember that I solved it. I should re read through my timer code.. I'm confident about it. I made it like.. 10 years ago before requestAnimationFrame existed and extended it with requestAnimationFrame as soon as it shipped xD Ok a quick look led me there: let timeout = now % 1000; timeout = timeout !== 0 ? 1000 - timeout : 1000;
@ELStalky
@ELStalky 3 жыл бұрын
I do not quite understand how that is supposed to work consistently. Can't you still get too much drift from setTimeout? E.g. going from underlying time difference of 16.4999 to 17.5001, yielding a jump in the UI from 16 to 18. I actually implemented a countdown just a few weeks ago. I think i settled for using a time difference while updating the UI a few times every second, but not every frame. So when the drift hits a boundary you get one interval that is slightly off but no numbers are skipped.
@jakearchibald
@jakearchibald 3 жыл бұрын
It'd have to drift over 1000ms to get the wrong number, and the drift correction should stop it getting anywhere near that
@rajatgupta08
@rajatgupta08 3 жыл бұрын
How did you got to know about drift??
@jakearchibald
@jakearchibald 3 жыл бұрын
I think I first encountered it by implementing a timer and seeing it glitch. However, I now know about it in more detail by reading the spec.
@rajatgupta08
@rajatgupta08 3 жыл бұрын
@@jakearchibald is there any way to check if particular website counter is drifting or not (through code) like if I want to check of any chess website.
@jakearchibald
@jakearchibald 3 жыл бұрын
@@rajatgupta08 You could record performance.now() at the start, then compare it to performance.now() at the end and see if the timer is showing the right thing
@pulga961
@pulga961 3 жыл бұрын
is there a way to stop it without AbortController?
@jakearchibald
@jakearchibald 3 жыл бұрын
You can adapt the solution to do it however you want 😀
@vitabramov89
@vitabramov89 3 жыл бұрын
Is this a GameOfThrones Whiskey on the background?))
@jakearchibald
@jakearchibald 3 жыл бұрын
Yep! Someone bought me it, and it was surprisingly nice
3 жыл бұрын
When did Chrome stop drifting? Or is it CPU architecture dependant? I ran into this trying to work on an embedded ARM system with Chromium and it started to drift really badly after a few weeks of running. Ended up using an external process for the events and just taking into account the delay in communication.
@jakearchibald
@jakearchibald 3 жыл бұрын
Ohh it's possible things change after weeks of running. Like I said, a random blocking task will cause a major drift (in all browsers)
@SimonBuchanNz
@SimonBuchanNz 3 жыл бұрын
You're going to get actual physical clock drifts at that time scale across separate hardware, it's why physical communication protocols have to have a clock signal. There's no software fix, except for something synchronizing them like NTP.
@Stoney_Eagle
@Stoney_Eagle 3 жыл бұрын
Is there an example why KZbins counter on ads are wrong and take 1 extra second 🤷‍♂️ yeah I notice...
@mfbx9da4
@mfbx9da4 3 жыл бұрын
Can't help but think this should be renamed "How to implement the tag". The counting part is not really relevant to the video and excellent insights.
@cintron3d
@cintron3d 3 жыл бұрын
I really want to know if step easing in the css solution would have avoided the CPU usage issue
@jakearchibald
@jakearchibald 3 жыл бұрын
We cover all of that at the end of the video. Only Safari optimises for step(), and it doesn't support animating content with CSS, so no 😀
@cintron3d
@cintron3d 3 жыл бұрын
@@jakearchibald yeah, I had paused the video to write that but I did watch to the end and really enjoyed it. Many thanks for doing this research and sharing the results!
@IDisposable
@IDisposable 3 жыл бұрын
What if you simply took the negative deltas and made them zero? (thus avoiding the double-render)
@jakearchibald
@jakearchibald 3 жыл бұрын
It isn't clear that they're a negative delta
@winterheat
@winterheat 3 жыл бұрын
The first method, even if the person starts the count (say go for exercise), comes back, and checks how long he has exercised for, if the computer did go into sleep mode, then it will not have counted the time when the computer was sleeping. The second method... so I think the concern is, since it is flooring the number, there can be a gap... (but 16 seconds? Even if it is off by 33ms, it take 30 seconds to go from floor(33.990), which is 33, to floor(35.023), which is 35 to show the gap (of missing 34)... so 16 seconds? meaning about 60ms slower each time?) So why not just make the interval 33 or 16 ms instead of 1000ms? If we are off by 0.033 seconds when we see the time, it is ok... but actually, when we floor the number, we can click start, and if we click "Stop" and it is 0.93s, we still see 0 and we are off by close to 1 second. So it is better to display 1 or 2 decimal places and know we can be off by that amount. Some time ago I checked, 33 ms was about the least amount of time between the handler being invoked in older browsers (IE8?), but now I do a `let start = Date.now(); void setTimeout(() => console.log(Date.now() - start), 0);` in Google Chrome, and it either prints out 1 or 2 on the MacBook Air M1, so it is 1/1000 or 2/1000 of a second
@jakearchibald
@jakearchibald 3 жыл бұрын
> So why not just make the interval 33 or 16 ms instead of 1000ms? Then you're using 30/60x the amount of CPU required. Basically the same reason requestAnimationFrame is a bad solution (which on a 60hz screen will be running every 16ms).
@winterheat
@winterheat 3 жыл бұрын
@@jakearchibald ok, I got to read up on requestAnimationFrame() and the rest of your solution... often I thought other webpages are doing tons of stuff underneath including showing ads and eating up 300MB to even 1GB just for one page sometimes anyway
@winterheat
@winterheat 3 жыл бұрын
@@jakearchibald I just saw the use case of KZbin broadcast count down from 2:34 to 0:00... it wouldn't look good if it is jumps from 2:12 to 2:10 directly... I wonder what if it is a solution such as updating every 160ms, so about 6 times per second, not too heavy on the CPU. If it is 100ms, then some second may appear as 0.9s and some appear as 1.1s but I guess not a big deal
@jakearchibald
@jakearchibald 3 жыл бұрын
@@winterheat why not use the solution I came up with?
@jakearchibald
@jakearchibald 3 жыл бұрын
@@winterheat the ideal solution in this video is only a few lines
@aliulanowar7802
@aliulanowar7802 3 жыл бұрын
thanks a lot for first Q answer => it's true
@ShawnBiddle
@ShawnBiddle 3 жыл бұрын
I feel like using `document.timeline` should immediately disqualify this as the "right" solution given that it's still in working draft, regardless if browsers technically implement it or not.
@jakearchibald
@jakearchibald 3 жыл бұрын
That's a bad take 😀. The HTML spec is a living spec, somewhat equivalent to a working draft. I guess you refuse to use HTML too?
@ShawnBiddle
@ShawnBiddle 3 жыл бұрын
​@@jakearchibald Maybe I'm just jaded by Google's premature use of the Shadow DOM v0 spec but there is an obvious difference between an accepted standard and one still labeled as experimental. Google in particular has been entirely too sanguine with considering its own implementation of a fledgling spec as ready for wide adoption. That's a "bad take" not unlike using the HTML living standard in an apples to oranges comparison to a Web API which isn't in living standard status. The "bad take" would be forgetting the Google privilege that if you shoot for the moon on a bad spec you have an army of developers to change direction (See: Polymer v2) which 99% of the web world does not have. Foisting potentially unstable tech on teams which can't afford the maintenance cost should the rug be pulled out from under them is a "bad take."
@jakearchibald
@jakearchibald 3 жыл бұрын
@@ShawnBiddle the web components thing was bad, agreed. However, the animation API I'm using here isn't Google only, it's in all browser engines, so the comparison to web components is apples/oranges.
@jakearchibald
@jakearchibald 3 жыл бұрын
Also, check out the list of editors in the spec. Mozilla + Apple + Google.
@ShawnBiddle
@ShawnBiddle 3 жыл бұрын
@@jakearchibald Totally fair enough, like I said I'm just jaded :D Though given how many things you went over in this video that are further along than WD in the spec that just doesn't work how you'd expect or explicitly ignores the spec I think we can both also agree that there's a big gray area between "use everything" and "use it after it's been stable for 5 years." Smaller companies are necessarily more conservative and a lot of the time companies with dev bandwidth they take for granted signal prematurely the readiness of feature XYZ. Google certainly isn't the only culprit nor is the web the only susceptible platform.
@halilbasmaci
@halilbasmaci 3 жыл бұрын
Thanksssssssa
@JonathanGray89
@JonathanGray89 3 жыл бұрын
I can't help but wonder if some of the code was inspired by a StackOverflow post that I participated in.
@JonathanGray89
@JonathanGray89 3 жыл бұрын
/questions/37187504/javascript-second-counter
@jakearchibald
@jakearchibald 3 жыл бұрын
@@JonathanGray89 nah, it wasn't based on anything particular from stackoverflow
@JonathanGray89
@JonathanGray89 3 жыл бұрын
@@jakearchibald Ahh the second example is extremely close to my answer there... Thanks for replying, and awesome video btw!
@victornpb
@victornpb 3 жыл бұрын
I did a similar kind of optimization when I wrote a FPS calculation library, it tried to predict when the next update should happen and bails all the calculations prematurely to save CPU making it a simple conditional integer branch. But in my case the scheduling mechanism is up to the consumer. github.com/victornpb/micro-fps
@oskrm
@oskrm 3 жыл бұрын
I'm the billionth viewer
@TimCaswell
@TimCaswell 3 жыл бұрын
I ended up with a similar solution when I needed a way to schedule cron-like actions on a website (some run every second, some at 8pm every day, some every hour, etc) github.com/creationix/family-dash/blob/main/modules/schedule.js
@TesterAnimal1
@TesterAnimal1 3 жыл бұрын
Seems to me the spec is wrong and was designed very lazily.
@jakearchibald
@jakearchibald 3 жыл бұрын
Which spec?
@hobbyturystaSEO
@hobbyturystaSEO 3 жыл бұрын
webworkes can make it more easier I think
@jakearchibald
@jakearchibald 3 жыл бұрын
I don't see how 😀
@hobbyturystaSEO
@hobbyturystaSEO 3 жыл бұрын
@@jakearchibaldby fetching data every 999milisec
@jakearchibald
@jakearchibald 3 жыл бұрын
@@hobbyturystaSEO I don't think that solves it, but I might be missing something
@hobbyturystaSEO
@hobbyturystaSEO 3 жыл бұрын
@@jakearchibald I just think about the idea no to animate every 1000ms but fetch data from web worker every999ms and 001ms to pain(render) just to save CPU. take it easy :>
@feihcsim7045
@feihcsim7045 3 жыл бұрын
🤯
@mfbx9da4
@mfbx9da4 3 жыл бұрын
How come Houdini didn’t come up in this chat?
@jakearchibald
@jakearchibald 3 жыл бұрын
Why should it have? What difference does it make?
@mehmetedex
@mehmetedex 3 жыл бұрын
javascript is a language that you can only learn how to count in 24min
From nothin’ to gzip - HTTP 203
29:19
Chrome for Developers
Рет қаралды 22 М.
Top 10 performance pitfalls - HTTP 203
36:31
Chrome for Developers
Рет қаралды 37 М.
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 83 МЛН
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 42 МЛН
They Chose Kindness Over Abuse in Their Team #shorts
00:20
I migliori trucchetti di Fabiosa
Рет қаралды 12 МЛН
WebAssembly Threads - HTTP 203
24:42
Chrome for Developers
Рет қаралды 23 М.
Generating your color palette in CSS | HTTP 203
28:02
Chrome for Developers
Рет қаралды 18 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
Scheduling Tasks - HTTP 203
16:39
Chrome for Developers
Рет қаралды 22 М.
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 403 М.
Cross-origin fetches - HTTP 203
23:42
Chrome for Developers
Рет қаралды 39 М.
AssemblyScript - HTTP 203
28:46
Chrome for Developers
Рет қаралды 23 М.
Streaming requests with fetch - HTTP 203
22:24
Chrome for Developers
Рет қаралды 36 М.
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 83 МЛН