couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Randall Leeds (JIRA)" <>
Subject [jira] [Updated] (COUCHDB-1130) binary optimization in couch_file
Date Tue, 19 Apr 2011 22:10:05 GMT


Randall Leeds updated COUCHDB-1130:

    Attachment: prof_bin_opt

Here's a runnable escript that exercises the original version, the patched version I uploaded
before, and a third version that tries to avoid the match context stuff I talked about.

Since the docs I linked are super confusing I'm not going to try to dig too far into explanations
by my findings are:

The original version is slowest.
The first patch is faster.
The third version (in the escript) is even faster.

We're talking 1us or 2us per call.

If there's a difference in memory consumption I can't tell from any of the output or any of
the erlang:system_info or erlang:memory functions. But then, I didn't try to mess with the
tracers or profiles to see what memory consumption is like mid-execution, so maybe all the
resources used are already freed at the end of the test.

Anyway. Do with this what you will. It's a small perf gain but if it's reproducible it's a
pretty critical code path to optimize so I say go for it?

I also tried flipping the order of the tests around just in case that had any affect, but
the results are consistent.

> binary optimization in couch_file
> ---------------------------------
>                 Key: COUCHDB-1130
>                 URL:
>             Project: CouchDB
>          Issue Type: Improvement
>          Components: Database Core
>    Affects Versions: 1.0.2
>            Reporter: Randall Leeds
>            Priority: Minor
>         Attachments: 0001-refactor-remove_block_prefixes-2-for-optimization.patch, prof_bin_opt
> I've had this patch sitting around since January and kept forgetting to file the ticket.
Hurray spring cleaning.
> Just for fun I ran erlc with +bin_opt_info, which gives information about how the Erlang
VM can optimize creating binary objects.
> What follows is the commit message from my patch.
> Even if I'm wrong about the last point, it can't hurt.
> What think you all?
> -------------------
> Running erlc with +bin_opt_info gives an INFO message stating that "matching
> anything else but a plain variable to the left of a binary pattern will prevent
> delayed sub binary optimization; SUGGEST changing argument order"
> I guess matching 0 is triggering this. If I understand correctly, this change
> will allow the compiler to skip creating a sub-binary that starts at the block
> boundary in the third clause and delay creation until we strip the leading byte
> in the 0 clause. This means one less 1-byte binary every time we read across a
> block boundary.

This message is automatically generated by JIRA.
For more information on JIRA, see:

View raw message