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

Abstract digest serialization #458

Merged
merged 4 commits into from Jun 22, 2017
Merged

Abstract digest serialization #458

merged 4 commits into from Jun 22, 2017

Conversation

ghost
Copy link

@ghost ghost commented Jun 22, 2017

On a trivial benchmark (commiting a view with a lot of new key/values), this series of patch introduce a 20-times speed-up (from around 60 seconds to around 3 seconds).

After some profiling, it looks like most of the time was spent on memcpy and to_hex. To remove unrequired copy/conversion, this series of patch abstract the signature of Hash.digest from Cstruct.t -> t to 'a Type.t -> 'a -> t.

Our trivial benchmark is based on irmin-mem and Irmin.Contents.Cstruct. Half of the speed-up comes from the serialisation of leafs (no encoding to hexadecimal anymore). The rest of the speed is gained from the 'hashing' of nodes (no intermediate JSON representation).

Further optimisation seems doable, but these simple one looks like the only one that requires some change in the functor signatures.

Note: for program where readability is more a matter than performances, it is still possible to dump hexadecimal on disk rather than raw bytes. This only requires an alternative implementation of Irmin.Contents.Cstruct.

@ghost ghost mentioned this pull request Jun 22, 2017
@samoht
Copy link
Member

samoht commented Jun 22, 2017

That look great, thanks!

I've done a quick review of the patch and I really like it. The RAW signature was really a hack, and using the first-class Type.t to use generic hashes instead is way more cleaner.

@samoht samoht merged commit b0415cc into mirage:master Jun 22, 2017
@@ -372,6 +372,9 @@ module Type: sig
(** [decode_json_lexemes] is similar to {!decode_json} but use an
already decoded list of JSON lexemes instead of a decoder. *)

val encode_cstruct: 'a t -> 'a -> 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.

Can you add some doc strings here? Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

See #460.

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

2 participants