Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39939

Re: Loop optimisation.

Path csiph.com!weretis.net!feeder8.news.weretis.net!news.mb-net.net!open-news-network.org!.POSTED.178.197.197.210!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Loop optimisation.
Date Wed, 14 Apr 2021 18:00:18 +0200
Organization PointedEars Software (PES)
Lines 92
Message-ID <2144986.iZASKD2KPV@PointedEars.de> (permalink)
References <s4snvd$cr0$1@dont-email.me> <86e3bc08-8877-45ce-9881-519d0a41b9c0n@googlegroups.com> <7904310.T7Z3S40VBb@PointedEars.de> <1110f942-cc14-45b2-966b-a4442461f170n@googlegroups.com> <9878253.nUPlyArG6x@PointedEars.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
Injection-Info gwaiyur.mb-net.net; posting-host="178.197.197.210"; logging-data="18561"; mail-complaints-to="abuse@open-news-network.org"
User-Agent KNode/4.14.10
Cancel-Lock sha1:gVvcxHle0eBGH0r6orEjOU9XSKQ=
X-User-ID U2FsdGVkX1+Pl9DCBFqGJQuzBAECQCV5dgHBl1zhabMbd1wwacQvQg==
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Xref csiph.com comp.lang.javascript:39939

Show key headers only | View raw


Thomas 'PointedEars' Lahn wrote:

> Michael Haufe (TNO) wrote: 
>> On Tuesday, April 13, 2021 at 7:20:42 PM UTC-5, Thomas 'PointedEars' Lahn
>> wrote:
>>> Michael Haufe (TNO) wrote:
>>> > Modern JavaScript engines use JIT compilation.
>>> AFAIK, they always did. What is new with “modern JavaScript engines”,
>>> IOW Google V8 (JavaScript), is only that the source code is compiled to
>>> native machine code instead of bytecode for a virtual machine.
>> 
>> Afraid not. They were all interpreters
>> 
>> - Firefox 3.1 was the first browser to introduce a JIT in version 3.1
>> called TraceMonkey [1] -
> 
> No, certainly not.  The wording “a new kind of Just-In-Time (JIT)
> compiler” does not imply that previous script engines interpreted source
> code.

This should clarify your misconception:

<https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/Bytecodes>

See also: 

<https://softwareengineeringdaily.com/2018/10/03/javascript-and-the-inner-workings-of-your-browser/#:~:text=The%20JavaScript%20engine%20is%20the,MacOS%2C%20Windows%2C%20or%20Linux.>

| [00:03:39] JM: Mathias Bynens, you are a software engineer at Google
| working on developer advocacy on the V8 team. Welcome to Software
| Engineering Daily.
| 
| […]
| 
| Give me a high-level perspective for the steps that are happening as this
| webpage with some various forms of JavaScript opens up.
| 
| [00:04:26] MB: […]
| 
| So the first thing that happens is the JavaScript source code goes into
| the JavaScript [engine’s] parser, which then takes that code and turns
| into an object-based representation, which we call an abstract syntax tree
| or an AST. Armed with AST, we can do some transformations on the code, do
| some [inaudible 00:05:06] here and there, but mainly the reason to have
| this AST is so that we can feed it into the first phase of execution,
| which is the interpreter.
| 
| So our interpreter in V8, it’s called Ignition. This interpreter generates
                                                       ^^^^^^^^^^^^^^^^^^^^^
| bytecode, which then runs in the interpreter. At that point we’re actually
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Since this is actually *compilation* (conversion of human-readable source 
code to machine-readable code), that part of the “interpreter” is actually
technically a _compiler_.

And since the machine-readable code is not “interpreted“ by the CPU 
firmware, but by a software, the "machine" that executes/“interprets” it is 
called a *virtual machine*.

IOW: a JIT-compiler converts source code to bytecode to be 
executed/“interpreted” by a virtual machine.

| running the JavaScript already, which is great. It’s like all we have to
| do is sparse it and then generate some bytecode in the interpreter, which
| can happen pretty quickly. So that’s great for a code that only needs to
| run once. For example, a lot of code on the web is code that initializes
| the webpage and you don’t run that in a loop very open, right? You only
| run it once. You load the page. So all that magic can happen in the
| interpreter with the bytecode that we generate.
| 
| But that’s not the end of the story, because sometimes code gets repeated
| quite often or we see that the same code paths get hit over and over and
| over again, and that point it might make sense to start optimizing those
| specific functions, right?
| 
| That’s why while we’re running the bytecode in the interpreter, JavaScript
| engines – Well, V8 does this, but all JavaScript engines basically do
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| this. […].
`----

JIT-compilation of source code to bytecode to be executed by a virtual 
machine is nothing unusual for so-called "interpreted languages".  For 
example, the same happens with Perl and Python code since time immemorial.

Unfortunately, there is a lot of confusion about this (on the Nets).

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-10 18:41 +0100
  Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-10 19:14 +0100
    Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:33 +0100
      Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-11 15:03 +0100
        Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-11 07:38 -0700
          Re: Loop optimisation. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-04-11 13:36 -0700
          Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-12 18:05 +0100
            Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 23:16 +0100
              Re: Loop optimisation. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2021-04-13 05:19 -0700
                Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-13 06:21 -0700
        Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 01:36 +0100
          Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-12 18:04 +0100
            Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-12 23:09 +0100
              Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-13 20:08 +0100
                Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-13 21:41 +0100
                Re: Loop optimisation. John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-14 18:24 +0100
  Re: Loop optimisation. Kristjan Robam <he12457@hotmail.com> - 2021-04-10 13:36 -0700
    Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:34 +0100
  Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-10 22:22 -0700
    Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-11 11:36 +0100
    Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 02:20 +0200
      Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-14 06:48 -0700
        Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 17:31 +0200
          Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 18:00 +0200
            Re: Loop optimisation. The Natural Philosopher <tnp@invalid.invalid> - 2021-04-14 19:25 +0100
            Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-14 23:10 +0200
              Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 09:45 -0700
            Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 09:43 -0700
              Re: Loop optimisation. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2021-04-17 21:45 +0200
                Re: Loop optimisation. Scott Sauyet <scott.sauyet@gmail.com> - 2021-04-18 19:06 -0700
          Re: Loop optimisation. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-04-17 08:50 -0700

csiph-web