John Lam 1997 — 2026

Algorithm complexity and modern CPU's

Remember your college introduction to data structures and algorithms course? Remember how you spent some time calculating the complexity cost of various algorithms based on big-O notation? There was one very important assumption that was made whenever you made those calculations: that the cost of accessing any address in memory was constant.

With today’s multi-tiered CPU cache architectures, it has become increasingly obvious (to those who care) that that assumption is no longer valid. A full cache miss on a modern 3GHz+ P4 will mean that you will waste ~1000 operations while waiting for the data to show up at the CPU.

Jan Gray wrote an excellent essay that attacks a data structure that is responsible for lousy performance characteristics on modern CPU’s: the venerable linked list. In this essay, you’ll see some of Jan’s prognostications on the future of CPU architectures. My favorite quote from this piece is “This scenario is so bad and so common that the microprocessor vendors use 80% of their transistor budgets for on-chip caches — Intel as glorified SRAM vendor.”.

2 archived reader comments

Kraen Munck (2003-11-28)

Well… Accessing any memory address is still O(1), i.e. pretty much constant. You know exactly how many clock cycles it’ll take (worst case) for your memory access to be completed.

What has changed is that newer processors are able to improve on the average access time by using caching.

But the point of the article still stands: let those who are so inclined create our storage structures - if they use a common interface, we can easily choose the one who has the best performance characteristics for the job.

joe chang (2003-12-05)

actually, the logic transistor count on P4 & Itanium2 is ~20M, Opteron is in the same range but that includes the logic for the integrated north bridge. one needs to exercise caution on transistor counts for logic and cache, cache transistors can be place with ~6X greater density than logic, hence if a cpu has 20M logic and 120M cache, then about the die areas for logic and cache are about equal. however, i do wish system & software designers would wake up to reality. the vast majority of memory in many applications today are either in disk cache or otherwise buffering data that in the past resided on disk, or basically has predictable access patterns such that residing off cpu in dram memory is no big deal. however, a good chunk of code, that has small block random access, where one word must be read to determine the next word, ie, not prefetchable. this should probably be implemented in sram. so a modern system might have 64-512M sram and a multi-GB dram bank. this is somewhat like the original Cray