@@ -12,14 +12,14 @@ V8 optimization inhibitors, or anything else..._
12
12
What the benchmark code does is, in order:
13
13
14
14
- build an empty tree ` T `
15
- - add 100000 elements to the beginning of ` T `
16
- - remove those 100000 elements by popping the first element of ` T ` 100000 times
17
- - add 100000 elements to the end of ` T `
15
+ - add 100000 values to the beginning of ` T `
16
+ - remove those 100000 values by popping the first value of ` T ` 100000 times
17
+ - add 100000 values to the end of ` T `
18
18
- split ` T ` at all 100000 positions, one after the other
19
- - remove the 100000 elements of ` T ` by popping the last element 100000 times
19
+ - remove the 100000 values of ` T ` by popping the last value 100000 times
20
20
21
21
Here are the first running times I measured for this implementation. It is not
22
- difficult to see that the implementation is not fast at all. 100000 elements is
22
+ difficult to see that the implementation is not fast at all. 100000 values is
23
23
not that much right?
24
24
25
25
``` sh
@@ -32,11 +32,11 @@ split: 144243ms
32
32
init: 6896ms
33
33
```
34
34
35
- However most of the motivation for those optimization steps came from applying
35
+ Most of the motivation for those optimization steps came from applying
36
36
the same benchmark to
37
37
[ another JavaScript implementation] ( https://github.com/qiao/fingertree.js )
38
- (actually, I copied the benchmark from Joe's repository). This made it obvious
39
- that my implementation was performing badly.
38
+ (actually, I initially copied the benchmark from Joe's repository).
39
+ This made it obvious that my implementation was performing badly.
40
40
41
41
``` sh
42
42
$ node ../fingertree.js/benchmark/benchmark.js
@@ -51,7 +51,7 @@ init: 141ms
51
51
## First implementation of lazy evaluation of subtrees
52
52
> f0ca58169a32140a8617625466f15489a3549124
53
53
54
- A Deep instance posseses a subtree which in some cases is not accessed at all
54
+ A Deep instance possesses a subtree which in some cases is not accessed at all
55
55
during the whole lifetime of its parent. So why build it? The idea is to delay
56
56
the construction of the object, which might be expensive, to a later point in
57
57
time using a proxy: a finger tree look-alike object that will construct the
@@ -80,8 +80,8 @@ structure defined as:
80
80
``` js
81
81
class Measured {
82
82
83
- constructor ( element , v ) {
84
- this .element = element ;
83
+ constructor ( value , v ) {
84
+ this .value = value ;
85
85
this .v = v ;
86
86
}
87
87
@@ -92,23 +92,22 @@ class Measured {
92
92
}
93
93
```
94
94
95
- where ` v ` is the value returned by ` Measure.measure( element ) ` . This wrapping
96
- allowed to give the same interface to elements , nodes, digits and trees with
95
+ where ` v ` is the measure returned by ` Measure.measure( value ) ` . This wrapping
96
+ allowed to give the same interface to values , nodes, digits and trees with
97
97
respect to computing measures. This approach has at least 2 problems:
98
98
99
99
- It introduces one additional level of indirection by wrapping all values.
100
- - The way it was implemented here caches measures for all elements . This might not
100
+ - The way it was implemented here caches measures for all values . This might not
101
101
be a good thing in settings where measures are big objects. Moreover, this
102
- is in contradiction with the * lazy way* of functional programming
103
- paradigms.
102
+ is in contradiction with the * lazy way* of functional programming paradigms.
104
103
105
104
However, there is a simpler way to solve the * common interface* problem. Indeed,
106
- the elements contained in the digits of the root tree can be measured
105
+ the values contained in the digits of the root tree can be measured
107
106
with the Measure object left unchanged, and starting from the subtree of the
108
107
root level we just need a modified Measure object that uses the interface of
109
108
Node2 and Node3 to compute the node measures. Never will digits contain objects
110
109
of different types, so patching the Measure object this way suffices, there is
111
- no need to give the same interface to nodes and elements .
110
+ no need to give the same interface to nodes and values .
112
111
113
112
Here are the measurements after the change:
114
113
@@ -127,7 +126,7 @@ Mostly noise for the moment. There must be something else to fix...
127
126
## Removing iterator loops and bindings for fixed size sequences
128
127
> 28f6ee08d33e2cb2b9d0e5cae69948a7013bc0b7
129
128
130
- At some point I decided to use a better tool than intuition to progress:
129
+ At this point I decided to use a better tool than intuition to progress:
131
130
profiling. This change is the first where I guided the pruning by looking at
132
131
the output of ` node --prof benchmark/tree.js ` using ` node-tick-processor `
133
132
from the [ tick] ( https://www.npmjs.com/package/tick ) package.
@@ -139,7 +138,7 @@ reduce( M.plus.bind( M ) , map( M.measure.bind( M ) , digit ) , M.zero( ) ) ;
139
138
```
140
139
141
140
However, since all four digit types are hard-coded has classes One, Two, Three
142
- and Four we could as well give a custom implementation of the measure( ) method
141
+ and Four we could as well give a custom implementation of the ` measure( ) ` method
143
142
to each digit type. For type Two for example, we have:
144
143
145
144
``` js
@@ -174,8 +173,8 @@ split method...
174
173
## Removing loops: part II
175
174
> 5b0af102240b3f0cfda7001f6b108a9811594c7a
176
175
177
- It turns out I didn't remove all occurences of this generic digit measurement
178
- method. Here are the running times after removing occurences of this method
176
+ It turns out I didn't remove all occurrences of this generic digit measurement
177
+ method. Here are the running times after removing occurrences of this method
179
178
from ` Deep.splitTree ` .
180
179
181
180
``` js
@@ -195,7 +194,7 @@ Better.
195
194
> 726354a3bd0591d767fb658d206680a6a74d2fbb
196
195
197
196
These two commits introduce specialized procedures for building trees from
198
- small lists and digits. These are really small trees, i.e. 0 to 4 elements , so
197
+ small lists and digits. These are really small trees, i.e. 0 to 4 values , so
199
198
why use the generic ` from_iterable ` constructor?
200
199
201
200
``` js
0 commit comments