Re: Optimising numeric division

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Joel Jacobson <joel(at)compiler(dot)org>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Optimising numeric division
Date: 2024-08-24 12:10:19
Message-ID: CAEZATCWw1OLCa_9ba6v_NpFqqobVeNxS10UboVFcMHCC0WCiLQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 24 Aug 2024 at 08:26, Joel Jacobson <joel(at)compiler(dot)org> wrote:
>
> On Sat, Aug 24, 2024, at 01:35, Joel Jacobson wrote:
> > On Sat, Aug 24, 2024, at 00:00, Joel Jacobson wrote:
> >> Since statistical tools that rely on normal distributions can't be used,
> >> let's look at the individual measurements for (var1ndigits=3, var2ndigits=3)
> >> since that seems to be the biggest slowdown on both CPUs,
> >> and see if our level of surprise is affected.
> >
> > Here is a more traditional benchmark,
> > which seems to also indicate (var1ndigits=3, var2ndigits=3) is a bit slower:
>
> I tested just adding back div_var_int64, and it seems to help.
>

Thanks for testing.

There does appear to be quite a lot of variability between platforms
over whether or not div_var_int64() is a win for 3 and 4 digit
divisors. Since this patch is primarily about improving div_var()'s
long division algorithm, it's probably best for it to not touch that,
so I've put div_var_int64() back in for now. We could possibly
investigate whether it can be improved separately.

Looking at your other test results, they seem to confirm my previous
observation that exact mode is faster than approximate mode for
var2ndigits <= 12 or so, so I've added code to do that.

I also expanded on the comments for the quotient-correction code a bit.

Regards,
Dean

Attachment Content-Type Size
v2-0001-Speed-up-numeric-division-by-always-using-the-fas.patch text/x-patch 42.3 KB
v2-0002-Test-code-for-div_var.patch text/x-patch 31.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joseph Koshakow 2024-08-24 12:44:40 Re: Remove dependence on integer wrapping
Previous Message Peter Eisentraut 2024-08-24 08:42:53 thread-safety: getpwuid_r()