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 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> References: <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 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+&. 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: See also: | [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: | | Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.