Tarantool development patches archive
 help / color / mirror / Atom feed
From: Oleg Babin via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Timur Safin <tsafin@tarantool.org>, v.shpilevoy@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH resend v2 08/11] lua, datetime: calculated attributes for datetimes
Date: Sat, 31 Jul 2021 09:31:03 +0300	[thread overview]
Message-ID: <378606f5-02d7-68a2-4efe-8fc68e7fef83@tarantool.org> (raw)
In-Reply-To: <045501d78592$8167c560$84375020$@tarantool.org>

Thanks for your reply. See my comment below.

On 31.07.2021 01:30, Timur Safin wrote:
> Hello Oleg again!
>
> :
> :
> : On 28.07.2021 13:34, Timur Safin via Tarantool-patches wrote:
> : > * introduced a set of calculated attributes to data object, e.g.:
> : >    - timestamp, seconds, microseconds, minute, or hours
> : >
> : > Part of #5941
> : > ---
> : >   src/lua/datetime.lua           | 51 ++++++++++++++++++++++------------
> : >   test/app-tap/datetime.test.lua | 17 +++++++++++-
> : >   2 files changed, 50 insertions(+), 18 deletions(-)
> : >
> : > diff --git a/src/lua/datetime.lua b/src/lua/datetime.lua
> : > index 9ec06d8d8..7a208cef9 100644
> : > --- a/src/lua/datetime.lua
> : > +++ b/src/lua/datetime.lua
> : > @@ -224,6 +224,36 @@ local function interval_serialize(self)
> : >       return { secs = self.secs, nsec = self.nsec }
> : >   end
> : >
> : > +local datetime_index = function(self, key)
> : > +    local attributes = {
> :
> : This change looks like pessimization because currently we need to
> : recreate "attributes" table
> :
> : for each function call. I suggest to use `attributes` as `__index` but
> : not such function.
>
> What would you say if I simply precache this attributes table in local,
> and then proceed this way?
> -----------------------------------------
> -local datetime_index = function(self, key)
> -    local attributes = {
> +local datetime_index_handlers = {
>           unixtime = function(self)
>               return self.secs
>           end,
> +
>           timestamp = function(self)
>               return tonumber(self.secs) + self.nsec / 1e9
>           end,
> +
>           nanoseconds = function(self)
>               return self.secs * 1e9 + self.nsec
>           end,
> +
>           microseconds = function(self)
>               return self.secs * 1e6 + self.nsec / 1e3
>           end,
> +
>           milliseconds = function(self)
>               return self.secs * 1e3 + self.nsec / 1e6
>           end,
> +
>           seconds = function(self)
>               return tonumber(self.secs) + self.nsec / 1e9
>           end,
> +
>           minutes = function(self)
>               return (tonumber(self.secs) + self.nsec / 1e9) / 60
>           end,
> +
>           hours = function(self)
>               return (tonumber(self.secs) + self.nsec / 1e9) / (60 * 60)
>           end,
> +
>           days = function(self)
>               return (tonumber(self.secs) + self.nsec / 1e9) / (60 * 60) / 24
>           end,
> +
>           add = function(self)
>               return function(self, o)
>                   return interval_increment(self, o, 1)
>               end
>           end,
> +
>           sub = function(self)
>               return function(self, o)
>                   return interval_increment(self, o, -1)
>               end
>           end,
>       }
> -    return attributes[key] ~= nil and attributes[key](self) or nil
> +
> +local datetime_index = function(self, key)
> +    return datetime_index_handlers[key] ~= nil and
> +           datetime_index_handlers[key](self) or nil
>   end
> -----------------------------------------
>
> I mean we still carefully check existence of an asked key, and return nil if
> there is no such key at all. Is it much different than what you've meant?
>
It's again about temporary tables. I gave a benchmark in one of the 
previous emails.

After changes it shoud be better. Thanks.


  reply	other threads:[~2021-07-31  6:31 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 10:34 [Tarantool-patches] [PATCH resend v2 00/11] Initial datetime support Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 01/11] build: add Christian Hansen c-dt to the build Timur Safin via Tarantool-patches
2021-07-29 23:40   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-31  9:22     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 02/11] lua: built-in module datetime Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 19:00     ` Timur Safin via Tarantool-patches
2021-07-31  6:29       ` Oleg Babin via Tarantool-patches
2021-07-31 16:51         ` Timur Safin via Tarantool-patches
2021-07-29 23:36   ` Vladislav Shpilevoy via Tarantool-patches
2021-07-30 15:39     ` Timur Safin via Tarantool-patches
2021-08-01 17:01       ` Vladislav Shpilevoy via Tarantool-patches
2021-08-01 20:23         ` Timur Safin via Tarantool-patches
2021-08-04 23:57           ` Vladislav Shpilevoy via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 03/11] lua, datetime: datetime tests Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 20:45     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 04/11] lua, datetime: display datetime Timur Safin via Tarantool-patches
2021-07-29 18:55   ` Oleg Babin via Tarantool-patches
2021-07-30 21:48     ` Timur Safin via Tarantool-patches
2021-07-31  6:29       ` Oleg Babin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 05/11] box, datetime: add messagepack support for datetime Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 06/11] box, datetime: datetime comparison for indices Timur Safin via Tarantool-patches
2021-07-29 18:56   ` Oleg Babin via Tarantool-patches
2021-07-30 22:18     ` Timur Safin via Tarantool-patches
2021-07-31  6:30       ` Oleg Babin via Tarantool-patches
2021-07-31  9:31         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 07/11] lua, datetime: proper datetime encoding Timur Safin via Tarantool-patches
2021-07-29 18:57   ` Oleg Babin via Tarantool-patches
2021-07-30 22:20     ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 08/11] lua, datetime: calculated attributes for datetimes Timur Safin via Tarantool-patches
2021-07-29 18:57   ` Oleg Babin via Tarantool-patches
2021-07-30 22:30     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches [this message]
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 09/11] lua, datetime: time intervals support Timur Safin via Tarantool-patches
2021-07-29 18:58   ` Oleg Babin via Tarantool-patches
2021-07-30 22:58     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches
2021-07-31  9:20         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 10/11] lua, datetime: unixtime, timestamp setters in datetime.lua Timur Safin via Tarantool-patches
2021-07-29 18:58   ` Oleg Babin via Tarantool-patches
2021-07-30 23:11     ` Timur Safin via Tarantool-patches
2021-07-31  6:31       ` Oleg Babin via Tarantool-patches
2021-07-31  9:54         ` Timur Safin via Tarantool-patches
2021-07-28 10:34 ` [Tarantool-patches] [PATCH resend v2 11/11] datetime: changelog for datetime module Timur Safin via Tarantool-patches
2021-07-29 18:55 ` [Tarantool-patches] [PATCH resend v2 00/11] Initial datetime support Oleg Babin via Tarantool-patches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=378606f5-02d7-68a2-4efe-8fc68e7fef83@tarantool.org \
    --to=tarantool-patches@dev.tarantool.org \
    --cc=olegrok@tarantool.org \
    --cc=tsafin@tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH resend v2 08/11] lua, datetime: calculated attributes for datetimes' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox