I am thinking that if the identifier list I am working from is also in order, there is a lot of opportunity for speeding up a binary search with some custom code. For instance if I see identifier 8000, I know that no further identifiers will be below 8000, so I can search only from there forward. I could also probably compare the two keys and guess how far forward I should set my midpoint to try to shorten my search.
Comparing ID strings or numbers is fast. If you do ten compares with binary search, you have found the 1/1000th part of your data which contain what you look for.

Can you really guess so good that you get to 0.1 % of where you wanted -- in code that is faster than ten compares? Maybe. The people recommending profiling was certainly right. Speed is often not intuitive. (Their advice to find the slow part first and optimize that is certainly good.)

Otherwise, you know the quote?

"Almost all programming can be viewed as an exercise in caching"

Your idea to just pull it into memory (if it fits) sounded good. But it is hard to give specific advice without more specific info.

Any solution to your problem will probably be based on doing some early handling of your data (or something else) that depends upon some details. You need to give more info, I believe.


In reply to Re: Speeding up data lookups by BerntB
in thread Speeding up data lookups by suaveant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.