Thread

  1. Re: Optimizing pg_trgm makesign() (was Re: WIP: Fast GiST index build)

    Tom Lane <tgl@sss.pgh.pa.us> — 2011-07-02T18:07:24Z

    I wrote:
    > I tweaked the patch a bit further (don't pessimize the boundary case
    > where there's exactly 4n+1 trigrams, avoid forcing trg1 into memory,
    > improve the comment) and attach that version below.  This is a little
    > bit faster but I still wonder if it's worth the price of adding an
    > obscure dependency on the header size.
    
    It occurred to me that we could very easily remove that objection by
    making the code dynamically detect when it's reached a suitably aligned
    trigram.  The attached version of the patch does it that way.  It seems
    to be a percent or so slower than my previous version, but I think that
    making the function robust against header changes is probably well worth
    that price.
    
    BTW, I also tried wrapping the first two loops in an "if (len > 4)"
    test, reasoning that the added complexity is useless unless the main
    loop will be able to iterate at least once, and surely most words are
    less than 15 bytes long.  While this did indeed make back the extra
    percent on my HPPA box, it made things a percent or so slower yet on my
    Intel box with gcc 4.4.5.  I think the compiler must be getting confused
    about what to optimize.  So I left that out of this version of the
    patch, but perhaps it deserves closer investigation.
    
    			regards, tom lane