Thread

Commits

  1. Eliminate divide in new fast-path locking code

  1. Get rid of integer divide in FAST_PATH_REL_GROUP() macro

    David Rowley <dgrowleyml@gmail.com> — 2025-04-14T02:09:16Z

    I noticed a while ago that the new fast-path locking code uses integer
    division to figure out the  fast-path locking group slot.  To me, this
    seems a bit unnecessary as FastPathLockGroupsPerBackend is always a
    power-of-two value, so we can use bitwise-AND instead.
    
    I don't think FAST_PATH_REL_GROUP() is in any particularly hot code
    paths, but still, having the divide in there isn't sitting well with
    me. Can we get rid of it?
    
    I've attached a patch for that. I also adjusted the method used to
    calculate FastPathLockGroupsPerBackend. Also, the Assert that was
    going on at the end of the loop in InitializeFastPathLocks() looked a
    little odd as it seems to be verifying something that the loop
    condition was checking already. I thought it was better to check that
    we end up with a power-of-two.
    
    Please see the attached patch.
    
    David
    
  2. Re: Get rid of integer divide in FAST_PATH_REL_GROUP() macro

    Tomas Vondra <tomas@vondra.me> — 2025-04-26T20:44:00Z

    On 4/14/25 04:09, David Rowley wrote:
    > I noticed a while ago that the new fast-path locking code uses integer
    > division to figure out the  fast-path locking group slot.  To me, this
    > seems a bit unnecessary as FastPathLockGroupsPerBackend is always a
    > power-of-two value, so we can use bitwise-AND instead.
    > 
    > I don't think FAST_PATH_REL_GROUP() is in any particularly hot code
    > paths, but still, having the divide in there isn't sitting well with
    > me. Can we get rid of it?
    > 
    
    Yes, we can get rid of the divide - if we assume power-of-two value
    (which seems fine, we already do that, IIRC).
    
    > I've attached a patch for that. I also adjusted the method used to
    > calculate FastPathLockGroupsPerBackend. Also, the Assert that was
    > going on at the end of the loop in InitializeFastPathLocks() looked a
    > little odd as it seems to be verifying something that the loop
    > condition was checking already. I thought it was better to check that
    > we end up with a power-of-two.
    > 
    > Please see the attached patch.
    > 
    
    Thanks. Those changes seem fine to me to.
    
    Do you intend to push these, or do you want me to do it?
    
    
    regards
    
    -- 
    Tomas Vondra
    
    
    
    
    
  3. Re: Get rid of integer divide in FAST_PATH_REL_GROUP() macro

    David Rowley <dgrowleyml@gmail.com> — 2025-04-26T23:55:13Z

    On Sun, 27 Apr 2025 at 08:44, Tomas Vondra <tomas@vondra.me> wrote:
    > Thanks. Those changes seem fine to me to.
    
    Thanks for checking.
    
    > Do you intend to push these, or do you want me to do it?
    
    I made a few tweaks to the comments and pushed.
    
    David