[squeak-dev] efficient DateAndTime

David T. Lewis lewis at mail.msen.com
Wed Apr 29 14:11:43 UTC 2020


Hi Chris,

On Tue, Apr 28, 2020 at 10:01:23PM -0500, Chris Muller wrote:
> Log entries are created often, I actually want to avoid creation of an
> interim DateAndTime in the first place.  I'm not even concerned about
> storage yet, but that will also benefit later.
> 

You can bypass the DateAndTime creation like this:

  (Time primPosixMicrosecondClockWithOffset: (Array new: 2)) first

The primitive is designed to accept either an uninitialized DateAndTime
with two instance variables or an Array of size 2. If you pass it a
two element array, it will store the posix microseconds in the first
slot, and the offset seconds in the second slot.

For database use, keep in mind that the primitive will not guarantee
unique values, and it may even give you time going "backwards" if
your system clock is being adjusted. So if you want fast, just do
what I suggest above, but if you need unique monotonically increasing
values, you will still want to use the logic in #posixMicrosecondClockWithOffset:

Also keep in mind that the posix microsecond value will be a SmallInteger
on a 64-bit image, and it will be a LargePositiveInteger on 32-bits, so
my may need to accomodate that difference when serializing it to the database.

Dave



More information about the Squeak-dev mailing list