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

Decompress (follow #210) #211

Merged
merged 4 commits into from
May 12, 2017
Merged

Decompress (follow #210) #211

merged 4 commits into from
May 12, 2017

Conversation

dinosaure
Copy link
Member

Better implementation of inflate/deflate function. We allocate only one time the needed buffer (input and output) used to inflate and deflate. Because these functions is used in a stop the world context, it's safe to use the same global buffer - otherwise, it's needed to have these buffer per serialization/deserialization contexts (and it's this case in sirodepac).

@samoht
Copy link
Member

samoht commented May 12, 2017

Force-pushed with a rebase on top of master

size_buffer)
(Deflate.default ~proof:B.proof_bytes level)
|> function
| Ok _ -> Cstruct.of_string @@ Buffer.contents res
Copy link
Member

Choose a reason for hiding this comment

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

@dinosaure can we avoid a copy here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can use a Bigstring instead a Bytes in decompress and use Cstruct.of_bigarray then in the best case. We can imagine, we allocate a Cstruct.t with Cstruct.create (Cstruct.len buff) as the result in the beginning (so, at most, the size of the input), but as I said we can do that in the best case only. Sometimes, the result of Deflate can be upper than the input (when the input is too small and when we store the huffman tree and the header). Obviously, it's not a common case but I already seen that.

May be, a good way is to reimplement the Buffer module but with Cstruct.t. Another implementation is to start with a Cstruct.t list, reverse the list at the end and concat all Cstruct.t.

Copy link
Member

Choose a reason for hiding this comment

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

ok makes sense. Let's merge this one as is, we can optimise if needed later.

then begin
Buffer.add_subbytes res output_buffer 0 (used_out t);
Some (Mstruct.of_string (Buffer.contents res))
end else Some (Mstruct.of_string (Buffer.contents res))
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid a string->bigarray copy here? Mstruct.of_cstruct (Cstruct.of_bigarry x) is pretty cheap, would be better if we could use this.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can optimize but the best best case, I think, is to have Mstruct.pick_bigstring.

Copy link
Member Author

Choose a reason for hiding this comment

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

Another point is to know exactly the size of the output (so output_size <> None).

@samoht
Copy link
Member

samoht commented May 12, 2017

All green, so merging!

@samoht samoht merged commit 5e6f7de into mirage:master May 12, 2017
samoht added a commit to samoht/opam-repository that referenced this pull request Jun 2, 2017
Changes:

* Add `ogit add-commit-parent` to add a new parent to a given commit
  (mirage/ocaml-git#208, @samoht)
* port to jbuilder (mirage/ocaml-git#209, @samoht)
* port to mtime 1.0 (mirage/ocaml-git#212, @dinosaure and @samoht)
* use Decompress instead of camlzip (mirage/ocaml-git#211, @dinosaure and @samoht)
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.

2 participants