Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[optimization] differential rule applications #1

Open
bddap opened this issue Jul 22, 2020 · 0 comments
Open

[optimization] differential rule applications #1

bddap opened this issue Jul 22, 2020 · 0 comments

Comments

@bddap
Copy link
Contributor

bddap commented Jul 22, 2020

The core reasoner (currently called TripleStore) is only capable of doing a round of reasoning over all tuples at once. This is optimal for the first round of reasoning, but causes a lot of re-computation during subsequent rounds.

If proof generation speed is found to be an issue, this optimization should be implemented:

Instead of, or in addition to fn apply. Add a function called e.g. insert_apply:

pub fn insert_apply(
    &self,
    triple: Triple,
    rule: &mut [Triple],
    instantiations: &mut Instantiations,
    cb: &mut impl FnMut(&Instantiations),
);

insert_apply can skip much of the wasted computation by assuming that the tuples stored in self have already been processed that the provided triple is the only potentially novel fact.

Alternate, and possibly more efficient, versions of insert_apply:

pub fn insert_apply(
    &self,
    triples: &[Triple],
    rule: &mut [Triple],
    instantiations: &mut Instantiations,
    cb: &mut impl FnMut(&Instantiations),
);
pub fn insert_apply(
    &self,
    other: &TripleStore,
    rule: &mut [Triple],
    instantiations: &mut Instantiations,
    cb: &mut impl FnMut(&Instantiations),
);

For that last one, insert_apply may assume that other is already processed or may process other itself. That last one is effectively a binary operation that merges two triple stores together, making deductions in the process. It could be used to recursively build a larger TripleStore out of smaller ones.

bddap added a commit that referenced this issue Apr 22, 2021
This implements differential rule applications as suggested in #1

As a side effect of implementing that optimization I also reduced the cased where LowRule needed to be cloned within the hot path. The reduction in clones made a small difference but differential rule applications had the greated effect.

Before:
```
running 4 tests
test ancestry::infer_          ... bench:   2,339,370 ns/iter (+/- 36,027)
test ancestry::prove_          ... bench:   2,332,249 ns/iter (+/- 61,357)
test recursion_minimal::infer_ ... bench:      35,339 ns/iter (+/- 1,012)
test recursion_minimal::prove_ ... bench:      34,850 ns/iter (+/- 312)
```

After:
```
test ancestry::infer_          ... bench:   1,683,208 ns/iter (+/- 49,885)
test ancestry::prove_          ... bench:   1,792,665 ns/iter (+/- 22,206)
test recursion_minimal::infer_ ... bench:      17,601 ns/iter (+/- 457)
test recursion_minimal::prove_ ... bench:      23,608 ns/iter (+/- 677)
```

We see a ~24% improvment for the 20 node ancestry test case. The percentage improvement becomes larger as node count increases. The previous version was too slow to even include a benchmark with larger node count (I lost patience waiting.). The new version is fast enough to scale to larger node counts so I've added another couple larger benchmarks in this commit: `ancestry::infer_30` and `test ancestry::prove_30`
@bddap bddap mentioned this issue Apr 22, 2021
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant