Judy array: Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Stumpybumpo
m Replaced dead link to mirror
 
imported>Bender the Bot
m HTTP to HTTPS for SourceForge
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{Short description|Type of associative array}}
{{Short description|Implementation of an associative array}}
{{notability|date=April 2022}}
{{notability|date=April 2022}}
In [[computer science]], a '''Judy array''' is a [[data structure]] implementing a type of [[associative array]] with high performance and low memory usage.<ref>[https://patents.google.com/patent/US6735595B2/en Robert Gobeille and Douglas Baskins' patent]</ref> Unlike most other [[key-value store]]s, Judy arrays use no hashing, leverage compression on their keys (which may be integers or strings), and can efficiently represent sparse data; that is, they may have large ranges of unassigned indices without greatly increasing memory usage or processing time. They are designed to remain efficient even on structures with sizes in the peta-element range, with performance scaling on the order of O(log ''n'').<ref>{{Cite web|url=http://packages.debian.org/buster/libjudy-dev|title=Debian -- Details of package libjudy-dev in buster}}</ref> Roughly speaking, Judy arrays are highly optimized 256-ary [[radix tree]]s.<ref>Alan Silverstein, "[http://judy.sourceforge.net/application/shop_interm.pdf Judy IV Shop Manual]", 2002</ref>


Judy trees are usually faster than [[AVL tree]]s, [[B-tree]]s, [[hash table]]s and [[skip list]]s because they are highly optimized to maximize usage of the [[CPU cache]]. In addition, they require no tree balancing and no hashing algorithm is used.<ref>{{Cite web|url=http://judy.sourceforge.net/doc/10minutes.htm|title=A 10-Minute Description of How Judy Arrays Work and Why They Are So Fast}}</ref>
In [[computer science]], a '''Judy array''' is an early-2000s [[Hewlett-Packard]] hand-optimized implementation of a 256-ary [[radix tree]] that uses many situational node types to reduce latency from CPU [[cache-line]] fills.<ref name="patent">[https://patents.google.com/patent/US6735595B2/en Robert Gobeille and Douglas Baskins' patent]</ref><ref name="shop">Alan Silverstein, "[https://judy.sourceforge.net/application/shop_interm.pdf Judy IV Shop Manual]", 2002</ref> As a compressed radix tree, a Judy array can store potentially sparse integer- or string-indexed data with comparatively low memory usage and low read latency, without relying on hashing or tree balancing, and without sacrificing in-order traversal.<ref name="ten">{{Cite web|url=http://judy.sourceforge.net/doc/10minutes.htm|title=A 10-Minute Description of How Judy Arrays Work and Why They Are So Fast}}</ref> Per-operation latency scales as <math>O(\log n)</math>—as expected of a tree—and the leading constant factor is small enough that Judy arrays are suitable even to the peta-element range.<ref>{{Cite web|url=http://packages.debian.org/buster/libjudy-dev|title=Debian -- Details of package libjudy-dev in buster}}</ref> When applicable, they can be faster than implementations of [[AVL tree]]s, [[B-tree]]s, [[hash table]]s, or [[skip list]]s from the same time period.<ref name="ten" />{{Update inline|date=June 2025}}


==History==
==History==
The Judy array was invented by Douglas Baskins and named after his sister.<ref name="judy.sourceforge.net">{{cite web |url=http://judy.sourceforge.net/ |title=Home |website=judy.sourceforge.net}}</ref>
The Judy array was invented by Douglas Baskins over the years leading up to 2002 and named after his sister.<ref name="judy.sourceforge.net">{{cite web |url=https://judy.sourceforge.net/|title=Home|website=judy.sourceforge.net}}</ref>


==Benefits==
==Node types==
===Memory allocation===
Broadly, tree nodes in Judy arrays fall into one of three categories, though the implementation uses situational variations within each category:<ref name="shop" />
Judy arrays are [[Dynamic array|dynamic]] and can grow or shrink as elements are added to, or removed from, the array. The memory used by Judy arrays is nearly proportional to the number of elements in the Judy array.
* A '''linear''' node is a short, fixed-capacity, array-based [[association list]] meant to fit in one cache line. That is, such a node has an array of key bytes and a parallel array of values or pointers. Lookup is by [[linear search]] over the key array and then random access to the corresponding index in the value/pointer array.
* A '''bitmap''' node is a size-256 [[bit array|bitvector]] tracking which values/children are present and then a sorted list of corresponding values or pointers. Lookup is by [[Hamming_weight#Processor_support|population count]] of the bits up to the target index and then random access to the corresponding entry in the value/pointer array. The bitmap fits within a typical CPU cache line, and random access only loads one cache line from the sorted list, so for reading these nodes require at most two cache-line fills.
* An '''uncompressed''' node is a conventional [[trie]] node as an array of values/pointers. Lookup is by random access using the key byte as an index, which at the CPU level requires visiting one cache line.


===Speed===
Linear nodes are used for low branching, bitmap nodes for intermediate branching, and uncompressed nodes for high branching.<ref name="shop" />
Judy arrays are designed to minimize the number of expensive [[cache-line]] fills from [[random-access memory|RAM]], and so the algorithm contains much complex logic to avoid cache misses as often as possible. Due to these [[CPU cache|cache]] optimizations, Judy arrays are fast, especially for very large datasets. On data sets that are sequential or nearly sequential, Judy arrays can even outperform hash tables, since, unlike hash tables, the internal tree structure of Judy arrays maintains the ordering of the keys.<ref name="nothings">{{Cite web|url=http://www.nothings.org/computer/judy/|title = A performance comparison of Judy to hash tables}}</ref>


==Drawbacks==
==Advantages and disadvantages==
Judy arrays are extremely complicated. The smallest implementations are thousands of lines of code.<ref name="judy.sourceforge.net"/> In addition, Judy arrays are optimized for machines with 64 byte cache lines, making them essentially unportable without a significant rewrite.<ref name="nothings"/>
Due to [[CPU cache|cache]] optimizations, Judy arrays are fast, especially for very large datasets. On certain tasks involving data that are sequential or nearly sequential, Judy arrays can even outperform hash tables, since, unlike hash tables, the internal tree structure of Judy arrays maintains the ordering of the keys.<ref name="nothings">{{Cite web|url=http://www.nothings.org/computer/judy/|title=A performance comparison of Judy to hash tables}}</ref>
 
On the other hand, Judy arrays are not suitable for all key types, rely heavily on compile-time case-splitting (which increases both the compiled code size and the work involved in retuning for a new architecture<ref name="nothings"/>), make some concessions to older architectures that may not be relevant to modern machines, and do not exploit [[SIMD]].<ref name="shop" /> They are optimized for read performance over write performance.<ref name="shop" />


==See also==
==See also==
* [[Radix tree]]
* [[Radix tree]]
* [[Bitwise trie with bitmap]]
* [[Hash array mapped trie]]
* [[Hash array mapped trie]]


Line 26: Line 29:


==External links==
==External links==
*[http://judy.sourceforge.net/ Main Judy arrays site]
*[https://judy.sourceforge.net/ Main Judy arrays site]
*[http://judy.sourceforge.net/downloads/10minutes.htm How Judy arrays work and why they are so fast]
*[https://judy.sourceforge.net/downloads/10minutes.htm How Judy arrays work and why they are so fast]
*[http://judy.sourceforge.net/application/shop_interm.pdf A complete technical description of Judy arrays]
*[https://judy.sourceforge.net/application/shop_interm.pdf A complete technical description of Judy arrays]
*[http://www.nothings.org/computer/judy/ An independent performance comparison of Judy to Hash Tables]
*[http://www.nothings.org/computer/judy/ An independent performance comparison of Judy to Hash Tables]
*[https://github.com/JerrySievert/judyarray A compact implementation of Judy arrays in 1250 lines of C code]
*[https://github.com/JerrySievert/judyarray A compact implementation of Judy arrays in 1250 lines of C code]


[[Category:Associative arrays]]
[[Category:Associative arrays]]

Latest revision as of 21:11, 9 August 2025

Template:Short description Script error: No such module "Unsubst".

In computer science, a Judy array is an early-2000s Hewlett-Packard hand-optimized implementation of a 256-ary radix tree that uses many situational node types to reduce latency from CPU cache-line fills.[1][2] As a compressed radix tree, a Judy array can store potentially sparse integer- or string-indexed data with comparatively low memory usage and low read latency, without relying on hashing or tree balancing, and without sacrificing in-order traversal.[3] Per-operation latency scales as O(logn)—as expected of a tree—and the leading constant factor is small enough that Judy arrays are suitable even to the peta-element range.[4] When applicable, they can be faster than implementations of AVL trees, B-trees, hash tables, or skip lists from the same time period.[3]Template:Update inline

History

The Judy array was invented by Douglas Baskins over the years leading up to 2002 and named after his sister.[5]

Node types

Broadly, tree nodes in Judy arrays fall into one of three categories, though the implementation uses situational variations within each category:[2]

  • A linear node is a short, fixed-capacity, array-based association list meant to fit in one cache line. That is, such a node has an array of key bytes and a parallel array of values or pointers. Lookup is by linear search over the key array and then random access to the corresponding index in the value/pointer array.
  • A bitmap node is a size-256 bitvector tracking which values/children are present and then a sorted list of corresponding values or pointers. Lookup is by population count of the bits up to the target index and then random access to the corresponding entry in the value/pointer array. The bitmap fits within a typical CPU cache line, and random access only loads one cache line from the sorted list, so for reading these nodes require at most two cache-line fills.
  • An uncompressed node is a conventional trie node as an array of values/pointers. Lookup is by random access using the key byte as an index, which at the CPU level requires visiting one cache line.

Linear nodes are used for low branching, bitmap nodes for intermediate branching, and uncompressed nodes for high branching.[2]

Advantages and disadvantages

Due to cache optimizations, Judy arrays are fast, especially for very large datasets. On certain tasks involving data that are sequential or nearly sequential, Judy arrays can even outperform hash tables, since, unlike hash tables, the internal tree structure of Judy arrays maintains the ordering of the keys.[6]

On the other hand, Judy arrays are not suitable for all key types, rely heavily on compile-time case-splitting (which increases both the compiled code size and the work involved in retuning for a new architecture[6]), make some concessions to older architectures that may not be relevant to modern machines, and do not exploit SIMD.[2] They are optimized for read performance over write performance.[2]

See also

References

<templatestyles src="Reflist/styles.css" />

  1. Robert Gobeille and Douglas Baskins' patent
  2. a b c d e Alan Silverstein, "Judy IV Shop Manual", 2002
  3. a b Script error: No such module "citation/CS1".
  4. Script error: No such module "citation/CS1".
  5. Script error: No such module "citation/CS1".
  6. a b Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".

External links