<div dir="ltr"><div>I don't think the numbers could be meaningfully compared. The whole purpose of the yield* invocations is to enable process switching, which I don't think your jitted methods allow for. But then are you merely comparing yield* invocations against direct invocations? For sure, the yield* ones will be  much slower.</div><div>Let alone my implementation, which also uses yield* for #< , #- and #+, so it would be much slower than below as operators are surely well optimized by JS, we can just measure direct vs yield* for the main recursive invocation:</div><div><br></div><div>Number.prototype.benchFib = function benchFib() {<br>  return this < 2 ? 1 : (this - 1).benchFib() + (this - 2).benchFib() + 1<br>}<br><br>var t = performance.now();<br>(30).benchFib();<br>performance.now() - t</div><div><br></div><div>gives on my laptop in Firefox 920, 911, 919, 898</div><div><br></div><div>Versus</div><div><br></div><div>
<span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace"><span class="gmail-cm-variable">Number</span>.<span class="gmail-cm-property">prototype</span>.<span class="gmail-cm-property">benchFiby</span> <span class="gmail-cm-operator">=</span> <span class="gmail-cm-keyword">function</span><span class="gmail-cm-keyword">*</span> <span class="gmail-cm-def">benchFiby</span>() {</span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace">   <span class="gmail-cm-keyword">return</span> <span class="gmail-cm-keyword">this</span> <span class="gmail-cm-operator"><</span> <span class="gmail-cm-number">2</span> <span class="gmail-cm-operator">?</span> <span class="gmail-cm-number">1</span> : (<span class="gmail-cm-keyword">yield</span><span class="gmail-cm-operator">*</span> (<span class="gmail-cm-keyword">this</span> <span class="gmail-cm-operator">-</span> <span class="gmail-cm-number">1</span>).<span class="gmail-cm-property">benchFiby</span>()) <span class="gmail-cm-operator">+</span> (<span class="gmail-cm-keyword">yield</span><span class="gmail-cm-operator">*</span> (<span class="gmail-cm-keyword">this</span> <span class="gmail-cm-operator">-</span> <span class="gmail-cm-number">2</span>).<span class="gmail-cm-property">benchFiby</span>()) <span class="gmail-cm-operator">+</span> <span class="gmail-cm-number">1</span> <br></span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace">}</span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace"><br></span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace">var t = performance.now();<br>(30).benchFiby().next();<br>performance.now() - t</span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace"><br></span></span></span></div><div><span class="gmail-message-body-wrapper"><span class="gmail-message-flex-body"><span class="gmail-message-body gmail-devtools-monospace">gives 2998, 3125, 3116, 3140<br></span></span></span>

</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 15, 2021 at 3:41 PM Vanessa Freudenberg <<a href="mailto:vanessa@codefrau.net">vanessa@codefrau.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Florin,</div><div><br></div><div>wow, that looks exciting! </div><div><br></div><div>This is indeed a much more thorough Squeak-to-JS mapping, where mine is more of a "traditional" VM. I love it!</div><div><br></div><div>Since my original post I implemented a mockup of "my" new JIT scheme:</div><div><br></div><div><a href="https://squeak.js.org/docs/jit.md.html#sketch:contextproxieswithintrospectionandinlinecaching/newjitsketch/performanceestimate" target="_blank">https://squeak.js.org/docs/jit.md.html#sketch:contextproxieswithintrospectionandinlinecaching/newjitsketch/performanceestimate</a><br></div><div><img src="cid:ii_kmazl2oj0" alt="image.png" style="margin-right: 0px;" width="562" height="182"><br></div><div><div>You can play with it here: <a href="https://codepen.io/codefrau/pen/JjbmVGw" target="_blank">https://codepen.io/codefrau/pen/JjbmVGw</a></div><div></div></div><div><br></div><div>Could you share the performance numbers you are seeing for your benchFib, in comparison to SqueakJS or my mockup? I am curious if <font face="monospace">yield*</font> is the way to go. </div><div><br></div><div>Thanks for sharing! And congrats on your new job. My progress is slow too, I only work on it some weekends. But then, I'm not in a hurry :)</div><div><br></div><div>Vanessa<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 14, 2021 at 6:18 PM Florin Mateoc <<a href="mailto:florin.mateoc@gmail.com" target="_blank">florin.mateoc@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr"><div>Hi Vanessa,</div><div><br></div><div>Sorry for the delay in responding - as somebody who has been inspired by your SqueakJS project, I think I should mention that I am working on a related project, for now tentatively called JsSqueak.</div><div>In addition to the inspiration provided by SqueakJS, it also scratches my longstanding itch about compiling (transpiling) Squeak.</div><div><br></div><div>I hesitated to talk about it, as it is still a work in progress - after small bits and pieces that I worked on over a long period, I had the opportunity to spend a significant and uninterrupted chunk of time on it last summer, when I was unemployed for 3 months, and I was able to make good progress. I was optimistically thinking of releasing a first version before the end of last year, but after I started working on my new job, progress on JsSqueak has slowed down significantly. I must confess that I (and especially my wife) hesitate in recreating that productive unemployed situation :)</div><div><br></div><div>I started with Squeak 4.5 - I already had code transforming Smalltalk code to a form more suitable for translation - and I also started with VMMakerJS-dtl.18 for the plugin generation part. Of course, I had to heavily modify it, since I have to get rid of the stack usage for arguments/receiver and returns.<br></div><div>Both of these big parts are working. I also implemented most numbered primitives by hand - they are inlined at generation time in the methods calling them.<br></div><div>I am also taking advantage of the latest and greatest additions to JavaScript. I am, of course, using classes, and the parallel class-side hierarchy is implemented using statics. To implement green threads/process switching, all translated methods are implemented as generator functions, and all calls are through yield* expressions. The preemption/interrupt check points are inlined. With this, a process switch is achieved by simply yield-ing (in the process/semaphore primitives).<br></div><div>With this, the Integer>>#benchFib method is translated (as a method in Number.prototype, there is one more, simpler, implementation in BigInt) as:</div><div><br></div><div><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">*<span style="color:rgb(122,122,67)">_benchFib</span>() {<br>   <span style="color:rgb(0,51,179)">if </span>(<span style="color:rgb(131,0,145)">Number</span>.<span style="color:rgb(122,122,67)">isSafeInteger</span>(<span style="color:rgb(0,51,179)">this</span>.<span style="color:rgb(122,122,67)">valueOf</span>())) { <span style="color:rgb(140,140,140);font-style:italic">// Effective (inherited or local) source for #benchFib in SmallInteger<br></span><span style="color:rgb(140,140,140);font-style:italic">      /*Handy send-heavy benchmark*/<br></span><span style="color:rgb(140,140,140);font-style:italic">   /*(result // seconds to run) = approx calls per second*/<br></span><span style="color:rgb(140,140,140);font-style:italic">   /* | r t |<br></span><span style="color:rgb(140,140,140);font-style:italic">     t := Time millisecondsToRun: [r := 26 benchFib].<br></span><span style="color:rgb(140,140,140);font-style:italic">     (r // 1000) // t*/<br></span><span style="color:rgb(140,140,140);font-style:italic">   /*138000 on a Mac 8100//100*/<br></span><span style="color:rgb(140,140,140);font-style:italic">   </span><span style="color:rgb(0,51,179)">if </span>(<span style="color:rgb(135,16,148)">GlobalActivationCounter</span>-- < <span style="color:rgb(23,80,235)">0</span>) <span style="color:rgb(0,51,179)">yield</span>* <span style="color:rgb(122,122,67)">GlobalCheckForInterrupts</span>();<br><br>   <span style="color:rgb(0,51,179)">return </span>(<span style="color:rgb(0,51,179)">yield</span>* <span style="color:rgb(0,51,179)">this</span>.<span style="color:rgb(122,122,67)">_lt</span>( <span style="color:rgb(23,80,235)">2</span>)).<span style="color:rgb(135,16,148)">booleanValueOf</span>(<span style="color:rgb(6,125,23)">"questionMark:colon:"</span>) ? (<span style="color:rgb(23,80,235)">1</span>) : (<span style="color:rgb(0,51,179)">yield</span>* (<span style="color:rgb(0,51,179)">yield</span>* (<span style="color:rgb(0,51,179)">yield</span>* (<span style="color:rgb(0,51,179)">yield</span>* <span style="color:rgb(0,51,179)">this</span>.<span style="color:rgb(122,122,67)">_sub</span>( <span style="color:rgb(23,80,235)">1</span>)).<span style="color:rgb(122,122,67)">_benchFib</span>()).<span style="color:rgb(122,122,67)">_add</span>( <span style="color:rgb(0,51,179)">yield</span>* (<span style="color:rgb(0,51,179)">yield</span>* <span style="color:rgb(0,51,179)">this</span>.<span style="color:rgb(122,122,67)">_sub</span>( <span style="color:rgb(23,80,235)">2</span>)).<span style="color:rgb(122,122,67)">_benchFib</span>())).<span style="color:rgb(122,122,67)">_add</span>( <span style="color:rgb(23,80,235)">1</span>));<br>} <span style="color:rgb(0,51,179)">else </span><span style="color:rgb(140,140,140);font-style:italic">// No implementation for #benchFib in Float hierarchy, trigger a DNU<br></span><span style="color:rgb(140,140,140);font-style:italic">      </span><span style="color:rgb(0,51,179)">return yield</span>* <span style="color:rgb(0,51,179)">super</span>.<span style="color:rgb(122,122,67)">_benchFib</span>()<br>}<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">The top-level check for smallIntegers is because both SmallInteger and Float are mapped to Number.<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">The booleanValueOf call is for implementing the mustBeBoolean machinery (it actually translates directly to DNU, like it is done nowadays in Squeak).<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">Of course, in Boolean, booleanValueOf is just an alias for valueOf<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">As you can see, though, this is not terribly efficient, but there is room for improvement/optimizations. With more work, in this case, the _lt call could be replaced by the < operator, and even the _sub and _add calls could be optimized, <br>although not completely, since their result can morph into LargeInteger (mapped to BigInt).<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">As hinted above, SmallInteger is mapped to Number (in the safeInteger range), Float is mapped to Number as well, and LargeInteger is mapped to BigInt.<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">BlockClosure is mapped to Function, Boolean is mapped to Boolean, Character is mapped to String, weak references are implemented via WeakRef. <br>I have briefly considered also doing slightly higher-level mappings, for IdentitySet to Set and IdentityDictionary to Map, but this is not a priority.<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">The image is serialized sort of like a JavaScript storeString. No processes or contexts though, or rather they are not brought back in on the JavaScript side. Blocks are both stored and loaded.<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">Non-local returns, unwind blocks, resumable and restartable exceptions are implemented via JavaScript exception handling plus explicit handler block chains associated with the processes.<br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">The "image" starts with the global state loaded, but all processes are started from scratch instead of resumed. A non-UI image is thus trivially started.<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">One major todo left is hooking up the UI/browser. I did take vm.display.browser.js from SqueakJS and adapted the code in order to implement its numbered primitives, but I still have to work through squeak.js from the same to initialize <br>and hook up the display.<br><br></pre><pre style="background-color:rgb(255,255,255);color:rgb(8,8,8);font-family:"JetBrains Mono",monospace;font-size:9pt">Florin<br></pre></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 7, 2021 at 11:17 PM Vanessa Freudenberg <<a href="mailto:vanessa@codefrau.net" target="_blank">vanessa@codefrau.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <div dir="ltr">Hi all,<div><br></div><div>ideas for a faster SqueakJS JIT have been swirling around in my head for many years. This weekend I took the time to write some of them down:</div><div><br></div><div><a href="https://squeak.js.org/docs/jit.md.html" target="_blank">https://squeak.js.org/docs/jit.md.html</a><br></div><div><br></div><div>Feedback welcome!</div><div><br></div><div>Vanessa</div></div>
</blockquote></div>
</blockquote></div></div></div></div>
</blockquote></div>