[Vm-dev] SqueakJS named primitives in the interpreter modulej

David T. Lewis lewis at mail.msen.com
Wed Jan 25 02:46:01 UTC 2017


On Mon, Jan 23, 2017 at 04:17:42PM +0100, Bert Freudenberg wrote:
>  
> On Sat, Jan 21, 2017 at 5:06 AM, David T. Lewis <lewis at mail.msen.com> wrote:
> 
> >
> > I sent a git pull request for the new primitive, so hopefully you can
> > review it and include it in SqueakJS if it is not too horrible.
> 
> 
> Awesome! Merged.
> 
> To my considerable surprise, DateAndTime>>now seems to be 70 times faster
> > on SqueakJS when using this primitive along with the enhancements in the
> > UTCDateAndTime repository.
> 
> 
> Well, emulating a primitive is a lot more expensive on a slow VM like
> SqueakJS still is. So I'm not too, surprised, but happy nonetheless :)
> 

I was comparing DateAndTime class>>now with UTCDateAndTime versus the
DateAndTime class>>now in standard Squeak Chronology. Both of them call
primitives, but the new one is much faster.

Having said that, I can see that other DateAndTime functions are marginally
slower with UTCDateAndTime in SqueakJS. This is due to using large integer
arithmetic with no support from LargeIntegersPlugin. I'm guessing that if
one or two primitives from LargeIntegersPlugin could be implemented in
SqueakJS, it would provide a big performance boost for this particular
use case.

> 
> > I am inexperienced with JavaScript and Git, so in case any of this did not
> > get through, the proposed new function in Squeak.Primitives is:
> >
> >     primitiveUtcWithOffset: function(argCount) {
> >         var d = new Date();
> >         var posixMicroseconds = this.pos53BitIntFor(d.getTime() * 1000);
> >         var offset = -60 * d.getTimezoneOffset();
> >         if (argCount > 0) {
> >             // either an Array or a DateAndTime in new UTC format with two
> > ivars
> >             var stWordIndexableObject = this.vm.stackValue(0);
> >             stWordIndexableObject.pointers[0] = posixMicroseconds;
> >             stWordIndexableObject.pointers[1] = offset;
> >             this.popNandPushIfOK(argCount + 1, stWordIndexableObject);
> >             return true;
> >         }
> >         var timeAndOffset = [
> >             posixMicroseconds,
> >             offset,
> >         ];
> >         this.popNandPushIfOK(argCount + 1, this.makeStArray(
> > timeAndOffset));
> >         return true;
> >     },
> >
> 
> It looks fine. We could try to incorporate the microsecondClock function,
> but if milliseconds are good enough then this will do.
> 

I would vote to leave it as milliseconds. It looks to me like performance.now()
is designed for profiling, and it intentionally avoids following clock skew.
That seems right for the microsecondClock() function in SqueakJS, but for
primitiveUtcWithOffset it seems better to directly answer the platform's opinion
of current time and offset, which may legitimately be influenced by clock skew.
If microsecond precision is needed for some reason, it can be added later.

Dave



More information about the Vm-dev mailing list