Useless division(s) in interval_cmp_value

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Useless division(s) in interval_cmp_value
Date: 2021-09-26 17:01:53
Message-ID: 2629129.1632675713@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

While thinking about Isaac Morland's patch to add abs(interval),
I happened to notice that interval_cmp_value() seems rather
inefficently written: it's expending an int64 division -- or
even two of them, if the compiler's not very smart -- to split
up the "time" field into days and microseconds. That's quite
pointless, since we're immediately going to recombine the results
into microseconds. Integer divisions are pretty expensive, too,
on a lot of hardware.

I suppose this is a hangover from when the code supported float
as well as int64 time fields; but since that's long gone, I see
no reason not to do the attached.

regards, tom lane

Attachment Content-Type Size
skip-useless-division.patch text/x-diff 1.1 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-09-26 17:42:41 Re: Add missing function abs (interval)
Previous Message Justin Pryzby 2021-09-26 17:01:17 Re: typos (and more)