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

More efficient fix for #13559. #13638

Merged
merged 3 commits into from
Oct 20, 2015
Merged

More efficient fix for #13559. #13638

merged 3 commits into from
Oct 20, 2015

Conversation

hessammehr
Copy link
Contributor

This fix causes far fewer allocations than the previous PR #13632. Performance identical to C code.

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

for the third time, can we delete jl_ios_get_nbyte_int here now that it's unused?

@hessammehr
Copy link
Contributor Author

@tkelman Sure, should I do that?

I did some more benchmarking and it looks like memory-wise we're on par with the C version, but about 3x slower for something like this:

function bench_readInt64()
       buf = Array{Int64}(1000000)
       f = open("/dev/zero", "r")
       for i = 1:1000000
              buf[i] = myread(f, Int64)
       end
       close(f)
       return buf
end

Perhaps someone more experienced can say if this is a reasonable tradeoff.

@tkelman tkelman added the io Involving the I/O subsystem: libuv, read, write, etc. label Oct 16, 2015
@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

Yes, searching all of github for uses of jl_ios_get_nbyte_int shows you're deleting the only one that isn't in a fork of Julia. If I'm wrong and it's still used somewhere in base that I can't find, then the tests would hopefully show it.

@hessammehr
Copy link
Contributor Author

You're right. It would be a new pull request, is that okay? I don't know if there's such a thing as a followup pull request.

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

I think it would be better as a separate commit within this PR.

@vtjnash
Copy link
Member

vtjnash commented Oct 16, 2015

just adding a cross-reference to the past PR: #12281

@hessammehr
Copy link
Contributor Author

Since the C function is only used by this particular Julia function, a small change in the C code would fix #13559, without affecting the rest of Julia or performance. I will follow up with a separate pull request.

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

You could also force push over the same branch, either here or reopen #13620 then force push to your patch-1 branch.

@hessammehr hessammehr force-pushed the master branch 2 times, most recently from e45f72d to 8534af5 Compare October 16, 2015 06:38
@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

The commit went through, but looks like it caused a hang on Travis (e: and appveyor). Do you have a local source build, do you see the same thing in tests? What platform are you on?

@hessammehr
Copy link
Contributor Author

It could be loop I added. My computer just finished building LLVM; it'll be another ~20 min before I can confirm.

@nalimilan
Copy link
Member

I must be missing something, the only commit I can see here changes the C code. Did you destroy the PR when you force-pushed?

@hessammehr
Copy link
Contributor Author

Yes, this supersedes my previous attempt, which I still have on a local branch.

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

also viewable at 93ac74d and ea7060c

@nalimilan
Copy link
Member

OK.

The indentation fix didn't move the curly braces, though. Also, adding a test is the only way to make sure this doesn't regress in the future.

@hessammehr
Copy link
Contributor Author

@nalimilan I looked at the rest of the file and it seems to use the same style for loops.

The build hangs on both my linux boxes as well. This might be too invasive of a change as ios_readprep is used in a few other places. I'll post a better solution in a little bit. Tests will follow.

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

Could you squash the commits?

@hessammehr
Copy link
Contributor Author

Sorry, but how would you recommend I go about doing that?

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

You do git rebase -i and change from pick to squash on your latter two commits. Tests would also be good to add, if possible to do without draining entropy or requiring user input.

@hessammehr
Copy link
Contributor Author

Got it, thanks.

The main difficulty with tests is that it is hard to make assumptions about /dev/random. On the one hand, you want to drain entropy at least at some point to cause a ios_prepread to read a partial sequence, e.g. 6 bytes instead of 8. Doing that without requiring user input is tricky. How about a reading from a FIFO as a mock /dev/random?

@tkelman
Copy link
Contributor

tkelman commented Oct 16, 2015

If you can make a FIFO reproduce the conditions that were causing the EOFError without this PR, that sounds like a good test. Might have to be @unix_only if appveyor has any trouble with your test (worth running it through once to find out though)

@hessammehr
Copy link
Contributor Author

FIFOs work like a charm. Should I put the tests in a new .jl file?

@tkelman
Copy link
Contributor

tkelman commented Oct 17, 2015

nah, test/file.jl or test/iobuffer.jl should work fine

@hessammehr
Copy link
Contributor Author

I have no idea how to do this in Windows, unfortunately. Would it be worth adding a non-blocking test for n-byte read that worked on all platforms? It wouldn't cover the RNG case but that problem doesn't affect in Windows anyway.

@tkelman
Copy link
Contributor

tkelman commented Oct 17, 2015

Yeah if that wouldn't be much trouble to write, more tests is always good on principle.

@hessammehr
Copy link
Contributor Author

Is there anything else that needs to be done? Docs?

…e identical to baseline.

Fixed infinite loop in previous fix for JuliaLang#13559.

Do not throw EOFError if buffer already contains n bytes. JuliaLang#13559
Uses the qualified path to launch julia
@tkelman
Copy link
Contributor

tkelman commented Oct 20, 2015

This is pretty subtle to be worth mentioning in the docs I think. Thanks for the PR!

@vtjnash does this look okay to merge?

vtjnash added a commit that referenced this pull request Oct 20, 2015
@vtjnash vtjnash merged commit 5fbf28b into JuliaLang:master Oct 20, 2015
@pao
Copy link
Member

pao commented Oct 21, 2015

Thanks @hessammehr for pursuing this through the iterations. We appreciate the contribution!

@hessammehr
Copy link
Contributor Author

You're welcome! This is a pretty fantastic community; thanks for being so patient with me everyone.

@tkelman
Copy link
Contributor

tkelman commented Nov 29, 2015

Thoughts on whether this should be backported for 0.4.2?

tkelman pushed a commit that referenced this pull request Nov 29, 2015
…al to baseline.

Fixed infinite loop in previous fix for #13559.

Do not throw EOFError if buffer already contains n bytes. #13559

(cherry picked from commit 68442e2)
ref #13638
@vtjnash
Copy link
Member

vtjnash commented Nov 30, 2015

looks safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants