Skip to content

Commit b0ee116

Browse files
authored
Merge pull request #3141 from perspective-dev/cpp-opt
Performance optimization for `perspective-server`
2 parents 3a2b81e + 67eb60e commit b0ee116

27 files changed

+822
-430
lines changed

pnpm-lock.yaml

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/perspective-server/cpp/perspective/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,16 @@ if(PSP_WASM_BUILD)
250250
")
251251
endif()
252252
else()
253-
set(OPT_FLAGS " -O3 -g${DEBUG_LEVEL} ")
253+
set(OPT_FLAGS " \
254+
-O3 -g${DEBUG_LEVEL} \
255+
-mbulk-memory \
256+
-msimd128 \
257+
-mrelaxed-simd \
258+
-flto \
259+
--emit-tsd=perspective-server.d.ts \
260+
")
254261
if (PSP_WASM_EXCEPTIONS)
255-
set(OPT_FLAGS "${OPT_FLAGS} -fwasm-exceptions -flto --emit-tsd=perspective-server.d.ts ")
262+
set(OPT_FLAGS "${OPT_FLAGS} -fwasm-exceptions ")
256263
endif()
257264
endif()
258265
elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
@@ -295,6 +302,7 @@ elseif(PSP_CPP_BUILD OR PSP_PYTHON_BUILD)
295302
-O3 \
296303
-fexceptions \
297304
-g1 \
305+
-fopenmp-simd \
298306
")
299307
if (PSP_WASM_EXCEPTIONS)
300308
set(OPT_FLAGS "${OPT_FLAGS} -fwasm-exceptions ")
@@ -335,15 +343,9 @@ endif()
335343

336344
if (PSP_WASM64)
337345
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} \
338-
-mbulk-memory \
339-
-msimd128 \
340-
-mrelaxed-simd \
341346
-s MEMORY64=1 \
342347
")
343348
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
344-
-mbulk-memory \
345-
-msimd128 \
346-
-mrelaxed-simd \
347349
-s MEMORY64=1 \
348350
")
349351
endif()

rust/perspective-server/cpp/perspective/src/cpp/aggregate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ t_aggregate::t_aggregate(
2525
) :
2626
m_tree(tree),
2727
m_aggtype(aggtype),
28-
m_icolumns(std::move(std::move(icolumns))),
29-
m_ocolumn(std::move(std::move(ocolumn))) {}
28+
m_icolumns(std::move(icolumns)),
29+
m_ocolumn(std::move(ocolumn)) {}
3030

3131
void
3232
t_aggregate::init() {

rust/perspective-server/cpp/perspective/src/cpp/arg_sort.cpp

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,44 +38,76 @@ t_argsort_comparator::t_argsort_comparator(
3838

3939
bool
4040
t_argsort_comparator::operator()(t_index a, t_index b) const {
41-
const t_tscalar& first = m_v[a];
42-
const t_tscalar& second = m_v[b];
43-
4441
switch (m_sort_type) {
45-
case SORTTYPE_ASCENDING: {
46-
return (first < second);
47-
} break;
48-
case SORTTYPE_DESCENDING: {
49-
return (first > second);
50-
} break;
51-
case SORTTYPE_ASCENDING_ABS: {
52-
return std::abs(first.to_double()) < std::abs(second.to_double());
53-
} break;
54-
case SORTTYPE_DESCENDING_ABS: {
55-
56-
return std::abs(first.to_double()) > std::abs(second.to_double());
57-
} break;
58-
case SORTTYPE_NONE: {
59-
return a < b;
60-
}
42+
case SORTTYPE_ASCENDING:
43+
return t_argsort_comparator_impl<SORTTYPE_ASCENDING>(m_v)(a, b);
44+
case SORTTYPE_DESCENDING:
45+
return t_argsort_comparator_impl<SORTTYPE_DESCENDING>(m_v)(a, b);
46+
case SORTTYPE_ASCENDING_ABS:
47+
return t_argsort_comparator_impl<SORTTYPE_ASCENDING_ABS>(m_v)(a, b);
48+
case SORTTYPE_DESCENDING_ABS:
49+
return t_argsort_comparator_impl<SORTTYPE_DESCENDING_ABS>(m_v)(
50+
a, b
51+
);
52+
case SORTTYPE_NONE:
53+
return t_argsort_comparator_impl<SORTTYPE_NONE>(m_v)(a, b);
6154
}
6255

6356
return a < b;
6457
}
6558

59+
namespace {
60+
61+
void
62+
init_output(std::vector<t_index>& output) {
63+
for (t_index i = 0, loop_end = output.size(); i != loop_end; ++i) {
64+
output[i] = i;
65+
}
66+
}
67+
68+
} // anonymous namespace
69+
6670
void
6771
simple_argsort(
6872
std::vector<t_tscalar>& v,
6973
std::vector<t_index>& output,
7074
const t_sorttype& sort_type
7175
) {
72-
// Output should be the same size is v
73-
for (t_index i = 0, loop_end = output.size(); i != loop_end; ++i) {
74-
output[i] = i;
75-
}
76-
t_argsort_comparator cmp(v, sort_type);
76+
init_output(output);
7777

78-
std::sort(output.begin(), output.end(), cmp);
78+
switch (sort_type) {
79+
case SORTTYPE_ASCENDING: {
80+
std::sort(
81+
output.begin(),
82+
output.end(),
83+
t_argsort_comparator_impl<SORTTYPE_ASCENDING>(v)
84+
);
85+
} break;
86+
case SORTTYPE_DESCENDING: {
87+
std::sort(
88+
output.begin(),
89+
output.end(),
90+
t_argsort_comparator_impl<SORTTYPE_DESCENDING>(v)
91+
);
92+
} break;
93+
case SORTTYPE_ASCENDING_ABS: {
94+
std::sort(
95+
output.begin(),
96+
output.end(),
97+
t_argsort_comparator_impl<SORTTYPE_ASCENDING_ABS>(v)
98+
);
99+
} break;
100+
case SORTTYPE_DESCENDING_ABS: {
101+
std::sort(
102+
output.begin(),
103+
output.end(),
104+
t_argsort_comparator_impl<SORTTYPE_DESCENDING_ABS>(v)
105+
);
106+
} break;
107+
case SORTTYPE_NONE: {
108+
// output is already identity-initialized
109+
} break;
110+
}
79111
}
80112

81113
} // namespace perspective

rust/perspective-server/cpp/perspective/src/cpp/base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ root_pidx() {
707707

708708
bool
709709
is_internal_colname(const std::string& c) {
710-
return c == std::string("psp_");
710+
return c == "psp_";
711711
}
712712

713713
template <typename T>

rust/perspective-server/cpp/perspective/src/cpp/context_grouped_pkey.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ t_ctx_grouped_pkey::get_data(
155155
for (t_uindex aggidx = 0, loop_end = aggcols.size(); aggidx < loop_end;
156156
++aggidx) {
157157
const std::string& aggname = aggschema.m_columns[aggidx];
158-
aggcols[aggidx] = aggtable->get_const_column(aggname).get();
158+
aggcols[aggidx] = aggtable->_get_const_column(aggname);
159159
}
160160

161161
const std::vector<t_aggspec>& aggspecs = m_config.get_aggregates();
@@ -520,12 +520,12 @@ t_ctx_grouped_pkey::rebuild() {
520520
};
521521

522522
const auto* sortby_col =
523-
tbl->get_const_column(m_config.get_sort_by(child_col_name)).get();
523+
tbl->_get_const_column(m_config.get_sort_by(child_col_name));
524524

525525
const auto* parent_col =
526-
tbl->get_const_column(m_config.get_parent_pkey_column()).get();
526+
tbl->_get_const_column(m_config.get_parent_pkey_column());
527527

528-
const auto* pkey_col = tbl->get_const_column("psp_pkey").get();
528+
const auto* pkey_col = tbl->_get_const_column("psp_pkey");
529529

530530
std::vector<t_datum> data(nrows);
531531
tsl::hopscotch_map<t_tscalar, t_uindex> child_ridx_map;
@@ -651,9 +651,9 @@ t_ctx_grouped_pkey::rebuild() {
651651
const t_aggspec& spec = aggspecs[aggnum];
652652
if (spec.agg() == AGGTYPE_IDENTITY) {
653653
auto* scol =
654-
aggtable->get_column(spec.get_first_depname()).get();
654+
aggtable->_get_column(spec.get_first_depname());
655655
scol->copy(
656-
tbl->get_const_column(spec.get_first_depname()).get(),
656+
tbl->_get_const_column(spec.get_first_depname()),
657657
aggindices,
658658
1
659659
);

0 commit comments

Comments
 (0)