79
Automated Data Structure Generation: Refuting Common Wisdom Kyle Dewey, Lawton Nichols, Ben Hardekopf 1 University of California, Santa Barbara

Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Automated Data Structure Generation: Refuting Common Wisdom

Kyle Dewey, Lawton Nichols, Ben Hardekopf

1

University of California, Santa Barbara

Page 2: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Teaser

• Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy to work with

• In contrast, we find that declarative techniques are uniformly lightning fast (~30x to 9,000,000x)

• However, for previously unattempted complex data structures, declarative techniques lack usability

From the standpoint of automatically generatingintricate, highly constrained data structures:

2

Page 3: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Outline

• Background

• Simple example

• Usability problems

• Performance evaluation

3

Page 4: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Outline

• Background

• Simple example

• Usability problems

• Performance evaluation

4

Page 6: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Specifying Data Structure Generators

• Imperative approaches feature loops and assignment, and are focused on how to generate

• Declarative approaches lack imperative features, and allow for logical descriptions of high-level features focused on what to generate

Two general approaches: imperative and declarative

6

Page 7: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Common Wisdom

• Imperative techniques are fast, but potentially unwieldy

• Declarative techniques are slow, but easier to use

7

Page 8: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Our Observation: There are Hidden Caveats to This

Common Wisdom

Page 9: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Performance Caveat

• One 13 year old result

• Compares a SAT-based approach to a non-SAT-based approach

• SAT is not the only way to write declarative code

9

Imperative means fast?

Page 10: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Usability Caveat

• Most complex data structure ever generated: valid red/black trees

• These are not actually all that complicated

• Nothing considers operations on the data structures

10

Declarative means expressive?

Page 11: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Our Contribution

• Test using a declarative approach that is not SAT-based

• Test with more complex data structures, along with special variants of them

• E.g., red/black trees which will rebalance upon the insertion of some value k

11

Page 12: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Declarative Without SAT

• Our observation: related work has been incrementally moving towards implementing a constraint logic programming (CLP) engine

• We will use CLP directly as our declarative stand-in

• Re-use decades of existing work

12

Page 13: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

13

Page 14: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

14

Page 15: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

15

Page 16: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

16

Page 17: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

Covered in related work

17

Page 18: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

Novel to this work

18

Page 19: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

19

Page 20: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

20

Page 21: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

21

Page 22: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Data Structures• Sorted linked lists

• Red-black trees

• Array heaps

• ANI images (via grammars)

• Skip lists

• Splay trees

• B-trees

22

Page 23: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Special Variants

• For each of these data structures, we also defined a special variant of them which tends to indicate a more interesting version for testing purposes

• Tried to select variants that stressed data structure specific operations

• More details in the paper

23

Page 24: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Special Variants with an Operational Nature

• Red-black trees: need insertion and rebalancing

• Array heaps: need dequeueing

• Splay trees: need splay

• B-trees: need insertion and node splitting

24

We are the first to look at these operations inthe context of generation.

Page 25: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Outline

• Background

• Simple example

• Usability problems

• Performance evaluation

25

Page 26: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Example: Sorted Linked Lists

26

Page 27: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Sorted Linked Lists

• Each element is between 0 and K

• A list contains between 0 and N elements

• Each element is ≤ the element after it, if applicable

• I.e., the list is in ascending order

27

Page 28: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

28

Page 29: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element)

29

Page 30: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :-

30

Page 31: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :- 0 #=< Element

31

Page 32: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :- 0 #=< Element,

32

Page 33: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :- 0 #=< Element, Element #=< K

33

Page 34: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :- 0 #=< Element, Element #=< K.

34

Page 35: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“Each element is between 0 and K”

inBound(K, Element) :- 0 #=< Element, Element #=< K.

35

Page 36: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Sorted Linked Lists

• Each element is between 0 and K

• A list contains between 0 and N elements

• Each element is ≤ the element after it, if applicable

• I.e., the list is in ascending order

36

Page 37: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Sorted Linked Lists

• Each element is between 0 and K

• A list contains between 0 and N elements

• Each element is ≤ the element after it, if applicable

• I.e., the list is in ascending order

37

Page 38: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

38

Page 39: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)

39

Page 40: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).

40

Page 41: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :-

41

Page 42: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0

42

Page 43: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).

43

Page 44: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :-

44

Page 45: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :- N > 1

45

Page 46: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :- N > 1, Elm1 #=< Elm2

46

Page 47: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :- N > 1, Elm1 #=< Elm2, inBound(K, Elm1),

47

Page 48: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :- N > 1, Elm1 #=< Elm2, inBound(K, Elm1), NewN is N - 1,

48

Page 49: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

“A list contains between 0 and N elements in ascending order, all between 0 and K”

% sorted: (N, K, List)sorted(_, _, []).sorted(N, K, [Element]) :- N > 0, inBound(K, Element).sorted(N, K, [Elm1, Elm2|Rest]) :- N > 1, Elm1 #=< Elm2, inBound(K, Elm1), NewN is N - 1, sorted(NewN, K, [Elm2|Rest]).

49

Page 50: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Putting it All Together% sorted: (N, K, List)%% Query below:?- sorted(3, 4, List), label(List).

50

Page 51: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Putting it All Together% sorted: (N, K, List)%% Query below:?- sorted(3, 4, List), label(List).

51

Page 52: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Putting it All Together% sorted: (N, K, List)%% Query below:?- sorted(3, 4, List), label(List).

List = [] ;List = [0] ;...List = [1, 3, 3] ;...List = [2, 2, 4] ;...

52

Page 53: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Outline

• Background

• Simple example

• Usability problems

• Performance evaluation

53

Page 54: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Fundamental Problem: Not Everything is as

Simple as a Sorted List

54

Page 55: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-Tree Invariants

• Include:

• Every node has at most m children

• All leaves appear in the same level

• Decidedly logical in nature

• Easy to express declaratively

Page 56: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

An Operational Twist

• The invariants before define what a B-tree is

• What if we are interested in testing operations on B-trees, specifically with trees intentionally designed to stress corner cases?

• Under specific conditions, tree structure must radically change upon element insertion

• Requires us to explain operations to the generator

56

Page 57: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)... 57

Page 58: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)... 58

How to implement?

Page 59: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)... 59

Imperative Setting: Implement Directly

Page 60: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

60

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Actual Imperative Implementation Code (Korat)

Imperative Specification

Page 61: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

61

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Page 62: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

62

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Page 63: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

63

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Page 64: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

64

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Page 65: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 1...

65

void insertNonFull(Node x, int k) { int i = x.n; if (x.leaf) { while (i >= 1 && k < x.key[i]) { x.key[i + 1] = x.key[i]; i = i - 1; }....

Page 66: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)...

=> ???

66

Declarative Setting: Logical Implication

Page 67: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)... 67

Page 68: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

B-TREE-INSERT-NONFULL(x, k)1: i <- n[x]2: if leaf[x]3: then while i ≥ 1 && k < keyi[x]4: do keyi+1[x] <- keyi[x]5: i <- i - 16: keyi+1[x] <- k7: n[x] <- n[x] + 18: DISK-WRITE(x)9: else while i ≥ 1 && k < keyi[x]10: do i <- i - 111: i <- i + 112: DISK-READ(ci[x])13: if n[ci[x]] = 2t - 114: then B-TREE-SPLIT-CHILD(...)... 68

Page 69: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Our Observation: Imperative Features are Desirable for Modeling Operations on

Data Structures

69

Page 70: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Outline

• Background

• Simple example

• Usability problems

• Performance evaluation

70

Page 71: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Measuring Performance

• Tested all aforementioned data structures and their special variants on Korat, UDITA, and CLP (using GNU Prolog)

• Measured how quickly all data structures within certain bounds could be generated, with a 30 minute timeout

71

Page 72: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Small Bounds

0.00100

500.00075

1000.00050

1500.00025

2000.00000

Lists Red-Black Heaps Image Skip Splay B-Trees

Korat UDITA CLP

72

Seconds(lower isbetter)

Page 73: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Small Bounds

0.00100

500.00075

1000.00050

1500.00025

2000.00000

Lists Red-Black Heaps Image Skip Splay B-Trees

Korat UDITA CLP

73

Seconds(lower isbetter)

UDITA Is Extremely Slow

Page 74: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Small Bounds

0.00100

37.50075

75.00050

112.50025

150.00000

Lists Red-Black Heaps Image Skip Splay B-Trees

Korat CLP

74

Seconds(lower isbetter)

Page 75: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Small Bounds

0.00100

37.50075

75.00050

112.50025

150.00000

Lists Red-Black Heaps Image Skip Splay B-Trees

Korat CLP

CLP Barely Registers

75

Seconds(lower isbetter)

Page 76: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Medium Bounds

• UDITA times out on everything

• Korat times out on 5 / 14 experiments

• CLP is generally ~30x - 1,000x faster

• For B-trees, Korat and UDITA both timeout, but CLP completes within a single millisecond

76

Page 77: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Large Bounds

• Korat and UDITA timeout on everything

• Depending on the data structure, CLP takes between ~70 seconds and just under 30 minutes

77

Page 78: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

On Usability• Informal argument

• No data structure took more than 90 minutes to specify in Korat or UDITA

• Code and algorithm reuse

• CLP variants always took significantly longer, up to 10 hours for B-trees

• Existing code all imperative, with little explanation of why it works

78

Page 79: Automated Data Structure Generation: Refuting Common Wisdom · Teaser • Common wisdom: imperative techniques are fast but inexpressive, while declarative techniques slow but easy

Conclusions

• CLP, a declarative technique, dramatically outperforms the imperative Korat and UDITA,defying common wisdom

• Korat and UDITA allow for much easier modeling than CLP, entirely because they are imperative in nature

79