Skip to content

Commit 3302435

Browse files
tbedf7cb
authored andcommittedJul 27, 2022
Replaced std::multimap with std::map<key,std::vector<>>
A callgrind analysis showed, that we spend much of our time inside the multimap functions. It seems that the multimap implementation provided by gcc requires memory allocations for equal_range and other lookups. This change results in a 120% performance increase on my system.
1 parent 82ef743 commit 3302435

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed
 

‎expr.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ comparison_op::comparison_op(prod *p) : bool_binop(p)
145145
auto &idx = p->scope->schema->operators_returning_type;
146146

147147
auto iters = idx.equal_range(scope->schema->booltype);
148-
oper = random_pick<>(iters)->second;
148+
oper = random_pick(random_pick(iters)->second);
149149

150150
lhs = value_expr::factory(this, oper->left);
151151
rhs = value_expr::factory(this, oper->right);
@@ -221,10 +221,10 @@ funcall::funcall(prod *p, sqltype *type_constraint, bool agg)
221221
retry:
222222

223223
if (!type_constraint) {
224-
proc = random_pick(idx.begin(), idx.end())->second;
224+
proc = random_pick(random_pick(idx.begin(), idx.end())->second);
225225
} else {
226226
auto iters = idx.equal_range(type_constraint);
227-
proc = random_pick<>(iters)->second;
227+
proc = random_pick(random_pick(iters)->second);
228228
if (proc && !type_constraint->consistent(proc->restype)) {
229229
retry();
230230
goto retry;
@@ -283,7 +283,7 @@ atomic_subselect::atomic_subselect(prod *p, sqltype *type_constraint)
283283
if (type_constraint) {
284284
auto idx = scope->schema->aggregates_returning_type;
285285
auto iters = idx.equal_range(type_constraint);
286-
agg = random_pick<>(iters)->second;
286+
agg = random_pick(random_pick(iters)->second);
287287
} else {
288288
agg = &random_pick<>(scope->schema->aggregates);
289289
}
@@ -299,7 +299,7 @@ atomic_subselect::atomic_subselect(prod *p, sqltype *type_constraint)
299299
auto idx = scope->schema->tables_with_columns_of_type;
300300
col = 0;
301301
auto iters = idx.equal_range(type_constraint);
302-
tab = random_pick<>(iters)->second;
302+
tab = random_pick(random_pick(iters)->second);
303303

304304
for (auto &cand : tab->columns()) {
305305
if (type_constraint->consistent(cand.type)) {

‎schema.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,34 @@ void schema::generate_indexes() {
1616
assert(type);
1717
for(auto &r: aggregates) {
1818
if (type->consistent(r.restype))
19-
aggregates_returning_type.insert(pair<sqltype*, routine*>(type, &r));
19+
aggregates_returning_type[type].push_back(&r);
2020
}
2121

2222
for(auto &r: routines) {
2323
if (!type->consistent(r.restype))
2424
continue;
25-
routines_returning_type.insert(pair<sqltype*, routine*>(type, &r));
25+
routines_returning_type[type].push_back(&r);
2626
if(!r.argtypes.size())
27-
parameterless_routines_returning_type.insert(pair<sqltype*, routine*>(type, &r));
27+
parameterless_routines_returning_type[type].push_back(&r);
2828
}
2929

3030
for (auto &t: tables) {
3131
for (auto &c: t.columns()) {
3232
if (type->consistent(c.type)) {
33-
tables_with_columns_of_type.insert(pair<sqltype*, table*>(type, &t));
33+
tables_with_columns_of_type[type].push_back(&t);
3434
break;
3535
}
3636
}
3737
}
3838

3939
for (auto &concrete: types) {
4040
if (type->consistent(concrete))
41-
concrete_type.insert(pair<sqltype*, sqltype*>(type, concrete));
41+
concrete_type[type].push_back(concrete);
4242
}
4343

4444
for (auto &o: operators) {
4545
if (type->consistent(o.result))
46-
operators_returning_type.insert(pair<sqltype*, op*>(type, &o));
46+
operators_returning_type[type].push_back(&o);
4747
}
4848
}
4949

‎schema.hh

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ struct schema {
3030
std::multimap<typekey, op> index;
3131
typedef std::multimap<typekey, op>::iterator op_iterator;
3232

33-
std::multimap<sqltype*, routine*> routines_returning_type;
34-
std::multimap<sqltype*, routine*> aggregates_returning_type;
35-
std::multimap<sqltype*, routine*> parameterless_routines_returning_type;
36-
std::multimap<sqltype*, table*> tables_with_columns_of_type;
37-
std::multimap<sqltype*, op*> operators_returning_type;
38-
std::multimap<sqltype*, sqltype*> concrete_type;
33+
std::map<sqltype*, std::vector<routine*>> routines_returning_type;
34+
std::map<sqltype*, std::vector<routine*>> aggregates_returning_type;
35+
std::map<sqltype*, std::vector<routine*>> parameterless_routines_returning_type;
36+
std::map<sqltype*, std::vector<table*>> tables_with_columns_of_type;
37+
std::map<sqltype*, std::vector<op*>> operators_returning_type;
38+
std::map<sqltype*, std::vector<sqltype*>> concrete_type;
3939
std::vector<table*> base_tables;
4040

4141
string version;

0 commit comments

Comments
 (0)
Please sign in to comment.