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

Improve merging of Char parsers #291

Merged
merged 2 commits into from Nov 3, 2021
Merged

Conversation

johnynek
Copy link
Collaborator

  1. If we have a single CharIn parser, we don't need to compute the union, just reuse it (which also saves recomputing the range of characters)
  2. return a Set in the union function, not a List, which can return a large list if you have duplicates in your set.

@johnynek johnynek requested a review from regadas October 30, 2021 02:32
@codecov-commenter
Copy link

codecov-commenter commented Oct 30, 2021

Codecov Report

Merging #291 (26f2b27) into main (0039bb2) will increase coverage by 0.45%.
The diff coverage is 100.00%.

❗ Current head 26f2b27 differs from pull request most recent head f1a3422. Consider uploading reports for the commit f1a3422 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
+ Coverage   95.98%   96.43%   +0.45%     
==========================================
  Files           8        8              
  Lines         997     1011      +14     
  Branches       88       81       -7     
==========================================
+ Hits          957      975      +18     
+ Misses         40       36       -4     
Impacted Files Coverage Δ
core/jvm/src/main/scala/cats/parse/BitSet.scala 85.71% <100.00%> (ø)
...shared/src/main/scala/cats/parse/LocationMap.scala 97.05% <100.00%> (+1.22%) ⬆️
core/shared/src/main/scala/cats/parse/Parser.scala 96.32% <100.00%> (+0.49%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0039bb2...f1a3422. Read the comment docs.

core/shared/src/main/scala/cats/parse/Parser.scala Outdated Show resolved Hide resolved
Comment on lines +2614 to +2615
val minBs: List[(Int, BitSetUtil.Tpe)] = many.map { case CharIn(m, bs, _) => (m, bs) }
Chain.one(Parser.charIn(BitSetUtil.union(minBs)).asInstanceOf[P0])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we have a version of union with Iterator and avoid the copy in minBs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we certainly could. I wasn't sure it was worth it because we already iterate through the number of parsers regularly, but the characters inside the parsers (which we have to iterate when allocating a new CharIn to compute the ranges) could be more expensive, which was what I was targeting here.

Do you want me to address this before merging?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can address this as a follow-up for sure!

Co-authored-by: Filipe Regadas <filiperegadas@gmail.com>
@regadas regadas merged commit e3c178e into main Nov 3, 2021
@regadas regadas deleted the oscar/optimize_merge_charin branch November 3, 2021 16:17
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

Successfully merging this pull request may close these issues.

None yet

3 participants