Improve Performance of TTFunk::Table::OS2#group_original_code_points_by_bit #83
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.
Abstruct
fix #82
Original code takes
O(N * M)
time where N is UNICODE_RANGES size and M is code_map keys size.Improved code takes
O(max(N, M))
time.Idea
Original code calls
r.cover?
with all pair ofUNICODE_RANGES
andcode_map keys
.This takes
O(N * M)
time.If
UNICODE_RANGES
andcode_map keys
are both sorted, firstUNICODE_RANGE
contains somecode_map keys
of the head flagment (or empty), nextUNICODE_RANGE
contains next flagment, and so on.This storategy loops
UNICODE_RANGES
andcode_map keys
indivisualy, so it takesO(max(N, M))
time.Performance Test Result
I measure
Problem: TTFunk::Subset#encode
time with #82 reproduction code.(English Font changed to 'spec/fonts/DejaVuSans.ttf')It's about 8x faster than master branch, still 4x slower than 1.5.1 branch.