Skip to content

reducible with BSONIndexUnsafe#26

Open
poncito wants to merge 2 commits into
ancapdev:masterfrom
poncito:transducers
Open

reducible with BSONIndexUnsafe#26
poncito wants to merge 2 commits into
ancapdev:masterfrom
poncito:transducers

Conversation

@poncito
Copy link
Copy Markdown
Contributor

@poncito poncito commented Oct 5, 2022

Implements a more efficient "break" when foldl-ing. I just reduce on an isbit type, that I call "BSONIndexUnsafe", instead of a BSONReader.

I test:

julia> buf = UInt8[]
       writer = BSONWriter(buf)
       writer[] = (;a=[1,2,3])
       close(writer)

       @btime begin
           reader = BSONReader($buf)
           reader["a"]["2"][Int64]
       end

       @btime begin
           reader = BSONReader($buf)
           reader["a"][3][Int64]
       end

Before:

17.576 ns (0 allocations: 0 bytes)
108.146 ns (2 allocations: 64 bytes)

and after

 17.618 ns (0 allocations: 0 bytes)
 17.911 ns (0 allocations: 0 bytes)

A few remarks:

  1. I'd like to remove the code duplication between:
  • function Transducers.__foldl__(rf, val, reader::BSONReader)
  • function Transducers.__foldl__(rf, val, indices::BSONIndices)
    but I don't know how, but it should be doable, no? Obviously the first method would rely on the second one.
  1. I'd like to remove the code duplication between:
  • Base.getindex(reader::BSONReader, target::Union{AbstractString, Symbol})
  • function Transducers.__foldl__(rf, val, indices::BSONIndices)
    That seems more tricky because of the name_len_and_match_ optimization.
  1. You will notice that the field el_type of BSONIndexUnsafe is of type Int. It should be a UInt8. But if I do that, the benchmark above runs in 60ns. I don't understand why my "fix" as any kind of impact. Any idea?

Thanks,

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 5, 2022

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 94.73684% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.07%. Comparing base (69e129a) to head (dc2b620).
⚠️ Report is 25 commits behind head on master.

Files with missing lines Patch % Lines
src/reader.jl 94.73% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #26      +/-   ##
==========================================
+ Coverage   89.88%   90.07%   +0.18%     
==========================================
  Files          13       13              
  Lines         811      846      +35     
==========================================
+ Hits          729      762      +33     
- Misses         82       84       +2     
Flag Coverage Δ
unittest 90.07% <94.73%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ancapdev
Copy link
Copy Markdown
Owner

ancapdev commented Oct 9, 2022

@poncito just letting you know I've seen the PR, but I'm quite busy at the moment and I think I need a little time to sit down and wrap my head around the changes here. Performance results look good though 👍

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.

3 participants