Skip to content

Commit 9754878

Browse files
authored
Merge pull request #54 from atom-community/cpp_interface
2 parents b59c00d + 819dbc4 commit 9754878

File tree

10 files changed

+407
-247
lines changed

10 files changed

+407
-247
lines changed

benchmark/result.txt

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,142 @@
1-
aminy@LAPTOP-DHBEBJRL  ~\Documents\GitHub\JavaScript\@atom-ide-community\zadeh   master ≣  [22:48]
2-
❯ pnpm benchmark
31

4-
> [email protected].3 benchmark C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh
2+
> [email protected].4 benchmark C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\fuzzaldrin-plus-fast
53
> npm run benchmark:small && npm run benchmark:regular && npm run benchmark:large && npm run benchmark:tree
64

75

8-
> [email protected].3 benchmark:small C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh
6+
> [email protected].4 benchmark:small C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\fuzzaldrin-plus-fast
97
> node benchmark/benchmark-small.js
108

119
====== Running test - query:nm ======
12-
zadeh vs. legacy: 0.19 ms | 0.52 ms
10+
zadeh vs. legacy: 0.19 ms | 0.51 ms
1311
length of the result: 100, length of the lines: 100
1412

1513
====== Running test - query:npm ======
16-
zadeh vs. legacy: 0.15 ms | 3.77 ms
14+
zadeh vs. legacy: 0.42 ms | 3.86 ms
1715
length of the result: 55, length of the lines: 100
1816

1917
====== Running test - query:node ======
20-
zadeh vs. legacy: 0.15 ms | 1.34 ms
18+
zadeh vs. legacy: 0.16 ms | 1.3 ms
2119
length of the result: 100, length of the lines: 100
2220

2321
====== Running test - query:grunt ======
24-
zadeh vs. legacy: 0.2 ms | 0.26 ms
22+
zadeh vs. legacy: 0.14 ms | 0.33 ms
2523
length of the result: 33, length of the lines: 100
2624

2725
====== Running test - query:html ======
28-
zadeh vs. legacy: 0.1 ms | 0.45 ms
26+
zadeh vs. legacy: 0.11 ms | 0.46 ms
2927
length of the result: 10, length of the lines: 100
3028

3129
====== Running test - query:doc ======
32-
zadeh vs. legacy: 0.23 ms | 3.71 ms
30+
zadeh vs. legacy: 0.26 ms | 3.69 ms
3331
length of the result: 87, length of the lines: 100
3432

3533
====== Running test - query:cli ======
36-
zadeh vs. legacy: 0.89 ms | 1.63 ms
34+
zadeh vs. legacy: 0.38 ms | 1.61 ms
3735
length of the result: 57, length of the lines: 100
3836

3937
====== Running test - query:js ======
40-
zadeh vs. legacy: 0.17 ms | 0.44 ms
38+
zadeh vs. legacy: 0.14 ms | 0.31 ms
4139
length of the result: 60, length of the lines: 100
4240

4341
====== Running test - query:jas ======
44-
zadeh vs. legacy: 0.15 ms | 0.5 ms
42+
zadeh vs. legacy: 0.14 ms | 0.48 ms
4543
length of the result: 19, length of the lines: 100
4644

4745
====== Running test - query:mine ======
48-
zadeh vs. legacy: 0.24 ms | 2.48 ms
46+
zadeh vs. legacy: 0.22 ms | 2.4 ms
4947
length of the result: 65, length of the lines: 100
5048

5149
====== Running test - query:stream ======
52-
zadeh vs. legacy: 0.15 ms | 1.26 ms
50+
zadeh vs. legacy: 0.16 ms | 1.29 ms
5351
length of the result: 19, length of the lines: 100
5452

5553

56-
> [email protected].3 benchmark:regular C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh
54+
> [email protected].4 benchmark:regular C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\fuzzaldrin-plus-fast
5755
> node benchmark/benchmark.js
5856

5957
====== Running test - query:index ======
6058
~10% of results are positive, mix exact & fuzzy
61-
zadeh vs. legacy: 26.6 ms | 42.98 ms
59+
zadeh vs. legacy: 27.41 ms | 42.58 ms
6260
length of the result: 6168, length of the lines: 66672
6361

6462
====== Running test - query:indx ======
6563
~10% of results are positive, Fuzzy match
66-
zadeh vs. legacy: 26.48 ms | 48.69 ms
64+
zadeh vs. legacy: 27.49 ms | 48.34 ms
6765
length of the result: 6192, length of the lines: 66672
6866

6967
====== Running test - query:walkdr ======
7068
~1% of results are positive, fuzzy
71-
zadeh vs. legacy: 23.62 ms | 15.56 ms
69+
zadeh vs. legacy: 25.83 ms | 15.7 ms
7270
length of the result: 504, length of the lines: 66672
7371
zadeh is SLOWER
7472

7573
====== Running test - query:node ======
7674
~98% of results are positive, mostly Exact match
77-
zadeh vs. legacy: 40.91 ms | 66.81 ms
75+
zadeh vs. legacy: 40.36 ms | 68.62 ms
7876
length of the result: 65136, length of the lines: 66672
7977

8078
====== Running test - query:nm ======
8179
~98% of results are positive, Acronym match
82-
zadeh vs. legacy: 38.32 ms | 61.2 ms
80+
zadeh vs. legacy: 38.94 ms | 64.32 ms
8381
length of the result: 65208, length of the lines: 66672
8482

8583
====== Running test - query:nm ======
8684
~98% of results + Fuzzy match, [Worst case scenario]
87-
zadeh vs. legacy: 38.38 ms | 51.83 ms
85+
zadeh vs. legacy: 38.7 ms | 48.69 ms
8886
length of the result: 65208, length of the lines: 66672
8987

9088
====== Running test - query:nm ======
9189
~98% of results + Fuzzy match, [Mitigation]
92-
zadeh vs. legacy: 39.13 ms | 52.08 ms
90+
zadeh vs. legacy: 38.19 ms | 57.74 ms
9391
length of the result: 65208, length of the lines: 66672
9492

9593
====== Running test - query:ndem ======
9694
~98% of results + Fuzzy match, [Worst case but shorter string]
97-
zadeh vs. legacy: 43.48 ms | 207.84 ms
95+
zadeh vs. legacy: 45.93 ms | 229.78 ms
9896
length of the result: 65124, length of the lines: 66672
9997

100-
Matching 66672 results for 'index' (Prepare in advance) took 284.09 ms
101-
Matching 66672 results for 'index' (cache) took 272.74 ms
102-
Matching 66672 results for 'index' (_legacy_) took 80.52 ms
98+
Matching 66672 results for 'index' (Prepare in advance) took 275.81 ms
99+
Matching 66672 results for 'index' (cache) took 274.02 ms
100+
Matching 66672 results for 'index' (_legacy_) took 81.18 ms
103101

104-
> [email protected].3 benchmark:large C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh
102+
> [email protected].4 benchmark:large C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\fuzzaldrin-plus-fast
105103
> node benchmark/benchmark-large.js
106104

107-
TwoLetter _legacy_ took 12058.96 ms
108-
TwoLetter direct filter took 2815.90 ms
109-
TwoLetter setCandidates took 396.62 ms
105+
TwoLetter _legacy_ took 10776.69 ms
106+
TwoLetter direct filter took 3234.20 ms
107+
TwoLetter setCandidates took 414.90 ms
110108
======
111-
ThreeLetter _legacy_ took 8741.91 ms
112-
ThreeLetter direct filter took 2859.64 ms
113-
ThreeLetter setCandidates took 377.44 ms
109+
ThreeLetter _legacy_ took 9632.80 ms
110+
ThreeLetter direct filter took 3286.15 ms
111+
ThreeLetter setCandidates took 383.19 ms
114112
======
115-
TwoLetter keybased filter took 3255.72 ms
116-
ThreeLetter keybased filter took 3694.09 ms
113+
TwoLetter keybased filter took 3776.86 ms
114+
ThreeLetter keybased filter took 4413.96 ms
117115
======
118-
setCandidates took 184.88 ms
119-
TwoLetter filter took 392.21 ms
120-
ThreeLetter filter took 395.06 ms
116+
setCandidates took 219.13 ms
117+
TwoLetter filter took 393.76 ms
118+
ThreeLetter filter took 406.25 ms
121119
======
122-
setCandidates keybased took 190.06 ms
123-
TwoLetter keybased filter took 392.12 ms
124-
ThreeLetter keybased filter took 399.40 ms
120+
setCandidates keybased took 227.17 ms
121+
TwoLetter keybased filter took 402.38 ms
122+
ThreeLetter keybased filter took 416.81 ms
125123

126-
> [email protected].3 benchmark:tree C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\zadeh
124+
> [email protected].4 benchmark:tree C:\Users\aminy\Documents\GitHub\JavaScript\@atom-ide-community\fuzzaldrin-plus-fast
127125
> node benchmark/benchmark-tree.js
128126

129-
TreeFilterer.setCandidates: took 2.03 ms
130-
TreeFilterer.filter text took 0.79 ms
131-
TreeFilterer.filter dips took 0.43 ms
132-
TreeFilterer.filter disp took 0.30 ms
133-
TreeFilterer.filter txt took 0.37 ms
134-
TreeFilterer.filter getBuffer took 0.28 ms
127+
TreeFilterer.setCandidates: took 2.21 ms
128+
TreeFilterer.filter text took 0.54 ms
129+
TreeFilterer.filter dips took 0.41 ms
130+
TreeFilterer.filter disp took 0.36 ms
131+
TreeFilterer.filter txt took 0.42 ms
132+
TreeFilterer.filter getBuffer took 0.29 ms
135133

136-
TreeFilterer.filter average: 0.434 ms
134+
TreeFilterer.filter average: 0.404 ms
137135

138-
filterTree text took 2.64 ms
139-
filterTree dips took 2.26 ms
140-
filterTree disp took 3.08 ms
141-
filterTree txt: took 2.35 ms
142-
filterTree getBuffer: took 2.33 ms
136+
filterTree text took 2.83 ms
137+
filterTree dips took 2.43 ms
138+
filterTree disp took 3.54 ms
139+
filterTree txt: took 2.77 ms
140+
filterTree getBuffer: took 2.37 ms
143141

144-
filterTree average: 2.532 ms
142+
filterTree average: 2.788 ms

binding.gyp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
{
33
"targets": [{
44
"target_name": "zadeh",
5-
"sources": [ "src/common.h", "src/options.h", "src/binding/node.cc", "src/binding/node.h", "src/scorer.h", "src/path_scorer.h", "src/filter.h", "src/query.h", "src/matcher.h", "src/binding/tree.h" ],
5+
"sources": [
6+
"src/zadeh.h", "src/common.h", "src/data_interface.h",
7+
"src/options.h", "src/scorer.h", "src/path_scorer.h", "src/filter.h", "src/query.h", "src/matcher.h",
8+
"src/ArrayFilterer.h", "src/TreeFilterer.h",
9+
"src/binding/node.cc", "src/binding/node.h"
10+
],
611
"include_dirs": [
712
"<!@(node -p \"require('node-addon-api').include\")"
813
],
@@ -37,7 +42,10 @@
3742
"/GL", # whole Program Optimization # /LTCG is implied with /GL.
3843
"/DNDEBUG" # turn off asserts
3944
],
40-
}
45+
},
46+
"ClCompile": {
47+
"LanguageStandard": "stdcpp17"
48+
},
4149
}
4250
},
4351
# Debug Settings
@@ -103,6 +111,9 @@
103111
"/wd5027" # move operator was implicitly defined as deleted
104112
],
105113
},
114+
"ClCompile": {
115+
"LanguageStandard": "stdcpp17"
116+
},
106117
}, # MSVC
107118
"xcode_settings": {
108119
'GCC_OPTIMIZATION_LEVEL': '0', # stop gyp from defaulting to -Os

src/ArrayFilterer.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#ifndef Zadeh_TreeFilterer_H
2+
#define Zadeh_TreeFilterer_H
3+
4+
#include "common.h"
5+
#include "options.h"
6+
#include "filter.h"
7+
8+
namespace zadeh {
9+
10+
template<typename ArrayType, typename ElementType = CandidateString>
11+
class ArrayFilterer {
12+
private:
13+
vector<std::vector<CandidateString>> partitioned_candidates{};
14+
ArrayType candidates_view; // TODO use a reference or a raw pointer?
15+
16+
public:
17+
ArrayFilterer() = default;
18+
19+
ArrayFilterer(ArrayType &&candidates) {
20+
set_candidates(forward<ArrayType>(candidates));
21+
}
22+
23+
auto set_candidates(const ArrayType &candidates) {
24+
25+
const auto N = get_size(candidates);
26+
const auto num_chunks = get_num_chunks(N);
27+
28+
29+
partitioned_candidates.clear();
30+
partitioned_candidates.resize(num_chunks);
31+
32+
auto cur_start = 0u;
33+
for (auto i = 0u; i < num_chunks; i++) {
34+
35+
auto chunk_size = N / num_chunks;
36+
// Distribute remainder among the chunks.
37+
if (i < N % num_chunks) {
38+
chunk_size++;
39+
}
40+
for (auto j = cur_start; j < cur_start + chunk_size; j++) {
41+
partitioned_candidates[i].emplace_back(get_at<ArrayType, ElementType>(candidates, j));
42+
}
43+
cur_start += chunk_size;
44+
}
45+
46+
// store a view of candidates in case filter was called
47+
candidates_view = candidates;
48+
}
49+
50+
51+
auto filter_indices(const std::string &query, const size_t maxResults = 0, const bool usePathScoring = true, const bool useExtensionBonus = false) {
52+
// optimization for no candidates
53+
if (partitioned_candidates.empty()) {
54+
return vector<size_t>();
55+
}
56+
57+
const Options options(query, maxResults, usePathScoring, useExtensionBonus);
58+
return zadeh::filter(partitioned_candidates, query, options);
59+
}
60+
61+
auto filter(const std::string &query, const size_t maxResults = 0, const bool usePathScoring = true, const bool useExtensionBonus = false) {
62+
auto res = vector<ArrayType>{};
63+
64+
if (candidates_view == nullptr) {
65+
return res; // return an empty vector (should we throw?)
66+
}
67+
68+
const auto filter_indices = filter(query, maxResults, usePathScoring, useExtensionBonus);
69+
70+
for (size_t i = 0, len = filter_indices.size(); i < len; i++) {
71+
res[i] = candidates_view[filter_indices[i]];
72+
}
73+
return res;
74+
}
75+
};
76+
77+
78+
} // namespace zadeh
79+
#endif

0 commit comments

Comments
 (0)