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

Add channel.advancePastByte, use it to improve revcomp #8103

Merged
merged 6 commits into from
Feb 1, 2018

Conversation

mppf
Copy link
Member

@mppf mppf commented Jan 2, 2018

PR #8045 added some messy rev-comp studies that improve performance by improving the I/O pattern. What the performance comes down to is two things:

  1. Copying large chunks of the input from the channel buffer in to the array to be used
  2. Using memchr to identify the relevant chunks of the input

I experimented with a version that used regexp format strings to replace the memchr call but that had unsatisfying performance.

This PR adds channel.advancePastByte in order to enable the expression of the fast I/O pattern in revcomp easily. Now the revcomp version does the following:

  • "mark" (indicate to the I/O system not to drop the buffer as we might return)
  • identify the offset of the newline (end of the sequence description)
  • identify the offset of the > (start of the next sequence)
  • "revert" (go back to where we "marked")
  • read the data again in one go with readBytes

I'm seeing a 10% speedup for this version beyond revcomp-buf.chpl, and it is much simpler.

While there, I noticed that qio_channel_advance might not set up the buffer in some cases, so added code to do that.

Closes #8105.

Reviewed by @benharsh - thanks!

// Scan forward until we get to the > (end of sequence)
input.advancePastByte(ascii(">"));
nextDescOffset = input._offset();
} catch UnexpectedEOFError {
Copy link

@psahabu psahabu Jan 2, 2018

Choose a reason for hiding this comment

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

Does the compiler currently support this pattern? I think it should, but right now it might need to be catch e: UnexpectedEOFError.

Copy link
Member Author

Choose a reason for hiding this comment

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

seems to work...

Copy link
Member Author

Choose a reason for hiding this comment

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

I bet that it's not matching on the type but rather I'm naming an error variable UnexpectedEOFError and it shadows the type. I.e. it's like I wrote catch e. I'll update it.

@bradcray
Copy link
Member

bradcray commented Jan 3, 2018

Stab in the dark to head off potential testing noise: does the need for PR #8116 have any implications for this one?

This version of the benchmark finds the terminators within the I/O
buffer and then reads the appropriate amount of data directly.
@mppf
Copy link
Member Author

mppf commented Feb 1, 2018

@benharsh - could you review this PR? we certainly talked about it. It passed full local testing in an earlier version - after review I plan to run that again. Thanks.

@benharsh benharsh self-requested a review February 1, 2018 17:13
Copy link
Member

@benharsh benharsh left a comment

Choose a reason for hiding this comment

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

Nice!

Some potential follow-up issues to think about:

  • This pattern feels different enough from other languages to warrant some kind of simple example somewhere.
  • It would be nice if we could pass arrays (at least DefaultRectangular) to channel.readBytes. This is probably a pretty simple change.

@mppf mppf merged commit 7f4798a into chapel-lang:master Feb 1, 2018
@mppf mppf deleted the revcomp-investigate branch February 1, 2018 18:45
@mppf
Copy link
Member Author

mppf commented Feb 1, 2018

@benharsh - not sure where to put an example but at least it's a documented function...

As far as adjusting readBytes, I made a note of that issue #7954.

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.

4 participants