Skip to content

Commit 346b856

Browse files
committed
doc-links(cs): a unit step no directive can give anything asks no memo (R1)
The unit memo of the previous commit was asked -- the run's lock taken, an entry made -- for every unit step, also when the unit has no directive or its index rules the name out, where the walk returned at once before. That is lock traffic and memory for most projects, which have no global usings. The test that walk starts with is now one function (usings_may_give), asked before the memo too. The work counts of the doc_mentions cost tests are those from before the memo again, except where unit directives can give the name: one memo probe per lookup there. Test: cs_unit_usings_across_files_work and cs_unit_usings_unchanged as before (768 -> 1520 steps; without the memo 17003 -> 64403). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 19783ed commit 346b856

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎src/pipeline/doc_links_cs.c‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4645,17 +4645,27 @@ static void using_visit(const cs_ctx_t *c, const cs_using_t *us, int id, const c
46454645
level_using(c, &us[id], q, a_type_name, fd);
46464646
}
46474647

4648+
/* False when none of a step's n directives can give the query anything:
4649+
* there are none, or the index shows no static candidates and no namespace
4650+
* that can contribute this name. *a_type_name: the name is some type's. */
4651+
static bool usings_may_give(const cs_ctx_t *c, int n, const cs_using_index_t *index,
4652+
const cs_query_t *q, bool *a_type_name) {
4653+
if (!n) {
4654+
return false;
4655+
}
4656+
*a_type_name = cbm_ht_get(c->ix->type_names, q->name) != NULL;
4657+
bool indexed = index && index->ready && c->ix->name_scopes_ready;
4658+
return !(indexed && !index->nentities && (!index->nnamespaces || !*a_type_name));
4659+
}
4660+
46484661
static void level_usings(const cs_ctx_t *c, const cs_using_t *us, int n,
46494662
const cs_using_index_t *index, const cs_query_t *q, cs_found_t *fd,
46504663
cs_active_rec_t *rec) {
4651-
if (!n) {
4664+
bool a_type_name = false;
4665+
if (!usings_may_give(c, n, index, q, &a_type_name)) {
46524666
return;
46534667
}
4654-
bool a_type_name = cbm_ht_get(c->ix->type_names, q->name) != NULL;
46554668
bool indexed = index && index->ready && c->ix->name_scopes_ready;
4656-
if (indexed && !index->nentities && (!index->nnamespaces || !a_type_name)) {
4657-
return; /* no static candidates, and no namespace can contribute this name */
4658-
}
46594669
size_t hi = 0;
46604670
size_t lo = indexed ? name_scope_range(c->ix, q->name, &hi) : 0;
46614671
/* A common name in a large repository must not make a small scope walk
@@ -4861,6 +4871,10 @@ static cs_unit_step_t *unit_step_at(cs_unit_memo_t *m, const char *key, bool *mi
48614871
/* What the unit's directives give the query after the region's (`fd`). */
48624872
static void unit_usings(const cs_ctx_t *c, const cs_unit_t *unit, const cs_query_t *q,
48634873
cs_found_t *fd) {
4874+
bool a_type_name = false;
4875+
if (!usings_may_give(c, unit->nusings, &unit->using_index, q, &a_type_name)) {
4876+
return; /* nothing to ask, nothing to remember */
4877+
}
48644878
cs_unit_memo_t *m = c->ix->unit_memo;
48654879
char key[CS_MEMO_KEY];
48664880
cs_unit_step_t *e = NULL;
@@ -4891,7 +4905,6 @@ static void unit_usings(const cs_ctx_t *c, const cs_unit_t *unit, const cs_query
48914905
level_usings(c, unit->usings, unit->nusings, &unit->using_index, q, fd, NULL);
48924906
return;
48934907
}
4894-
bool a_type_name = cbm_ht_get(c->ix->type_names, q->name) != NULL;
48954908
for (int i = 0; i < e->n && !found_decided(fd); i++) {
48964909
level_using(c, &unit->usings[e->ids[i]], q, a_type_name, fd);
48974910
}

0 commit comments

Comments
 (0)