This repository has been archived by the owner on Aug 13, 2018. It is now read-only.
Speed up set closure by using a fixed amount of memory. #45
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In a typical description of this algorithm -- and in the previous implementation
-- one has a todo set which contains pairs (prod_i, dot). Unfortunately this is
a slow way of doing things. Searching the set for the next item and removing it
is slow; and, since we don't know how many potential dots there are production,
the set is of potentially unbounded size, so we can end up resizing memory.
Since this function is the most expensive in the table generation, using a
HashSet (which is the "obvious" solution) is pretty slow.
However, we can reduce these costs through two observations:
from self.items.keys(). There's no point copying these into a todo list.
these cases is always 0, we don't need to store pairs: simply knowing which
prod_off's we need to look at is sufficient. We can represent these with a
fixed-size bitfield.
All we need to do is first iterate through the items in 1 and, when it's
exhausted, continually iterate over the bitfield from 2 until no new items have
been added.
On my machine, this speeds up the time needed to build the PHP LR table by 10%,
from 0.33s to 0.30s.