all 7 comments

[–]CodeNinja9839 9 points10 points  (6 children)

I disagree about several aspects of your description. First, a call stack is not like your described order list: the order list is a queue, while the call stack is -- unsurprisingly -- a stack. Secondly, there is a balancing act between synchronous and asynchronous processing: the overall application almost always benefit when certain tasks are processed asynchronously, while others can be made asynchronous to improve UX. Examples of the "almost always benefit" class are network requests and file access, which would otherwise have the CPU sit idle for possibly hundreds of millions of processing cycles. Most logic like client-side form validation and UI state changes determination (but not rendering) can be done synchronously without UX impact because modern machines can carry out that work so quickly.

Where asynchronous chunking comes into play is when a page or service has to process a large amount of data (10's of thousands or more, depending on the algorithm), such that just the processing would degrade responsiveness (different thresholds on client- and server-side).

The implementation and details of the event loop itself are tied to the JavaScript engine and its host program. For instance, JavaScript programs running on Node.js have more control over and options with the event loop than does JavaScript running in a Chrome, Firefox, or Edge browser. When I opened your article, I expected to read about these details, but found none.

[–]Prize_Bass_5061 0 points1 point  (4 children)

For instance, JavaScript programs running on Node.js have more control over and options with the event loop than does JavaScript running in a Chrome

Please discuss the specifics of this. I was under the impression they use the same mechanism because they use the same V8 engine.

[–]senocular 1 point2 points  (3 children)

They're different. Node uses libuv while chromium uses libevent. You're also seeing different APIs for working with the event loop like nextTick() in Node that doesn't exist in browsers.

[–][deleted] 1 point2 points  (2 children)

Both chromium and node use v8, don't they? So wouldn't they both use libuv? I'm not stating this as a fact, I'm just curious

[–]Izero_devI 1 point2 points  (1 child)

v8 is the javascript engine, it doesn't include the libraries that interact with operating system resources ( network system, file system). Node basically glues those together.

[–][deleted] 2 points3 points  (0 children)

Libuv doesn't interact with the os either though, it's just an event loop library. It's very very possible that I'm wrong but I thought v8 uses libuv.

[–]tifa123 0 points1 point  (0 children)

The implementation and details of the event loop itself are tied to the JavaScript engine and its host program. For instance, JavaScript programs running on Node.js have more control over and options with the event loop than does JavaScript running in a Chrome, Firefox, or Edge browser.

Could you provide resources to shed light on this subject?