Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Enhancements

* Improve formula generation performance by imposing tighter limits on variant simplification

### Bugfixes

* Fix parsing error during stats generation
Expand Down
10 changes: 8 additions & 2 deletions src/form/variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bool VariantsManager::update(Variant new_variant) {
return false;
}
const auto num_terms = new_variant.definition.numTerms();
if (num_terms > 500) { // magic number
if (num_terms > 200) { // limit term count to reduce complexity
Log::get().debug("Skipping variant with " + std::to_string(num_terms) +
" terms");
return false; // too many terms
Expand All @@ -49,6 +49,10 @@ bool VariantsManager::update(Variant new_variant) {
// return false;
// }
auto& vs = variants[new_variant.func];
// limit number of variants per function to reduce O(n^4) complexity
if (vs.size() >= 20) {
return false;
}
// prevent rapid increases of variant sizes
if (!std::all_of(vs.begin(), vs.end(), [new_variant](const Variant& v) {
return v.used_funcs.size() + 1 >= new_variant.used_funcs.size();
Expand Down Expand Up @@ -196,7 +200,9 @@ bool simplifyFormulaUsingVariants(
Formula& formula, std::map<std::string, int64_t>& num_initial_terms) {
VariantsManager manager(formula, num_initial_terms);
bool found = false;
while (manager.numVariants() < 200) { // magic number
size_t iterations = 0;
while (manager.numVariants() < 100 && iterations < 50) { // tighter limits
iterations++;
if (findVariants(manager)) {
found = true;
} else {
Expand Down