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
(Premature) optimization of nqp::join() on JVM #106
Conversation
|
|
|
@Benabik I did not compare timings against a properly-sized The JIT can potentially do exactly the same thing, but I don't think it's worth the effort to de-optimize the code now that I've already written it ;) |
|
Agressive manual inlining leads to harder to read code. I had wondered if you could get much of the speed improvement without adding so much code. It's also possible that the implementation of StringBuilder uses lower level loops for speed. What micro-benchmark improves? I could try it myself, since I suggested it. |
|
Ahem, Anyway, if you want to do this, more idiomatic code that does the same thing (untested, beware typos) is As a micro-benchmark, just call |
|
I appear to have mis-read your commit, my apologies. And looking at the code to still use StringBuilder, I see there's not a lot of difference in complexity anyway. When I read "premature optimization" and "manual inlining of library code", I worry a bit. Thank you for explaining things. In the meantime, I have to figure out how I broke my nqp.jvm... |
|
looks like my emailed reply didn't make it an hour ago; oh well; here it is: It's worth testing at least, since it's also conceivable the JIT can optimize the usual factoring better. |
|
I agree that it's worth looking into, but mostly for academic reasons. I would be very surprised if the JIT could optimize the less explicit code any better as |
|
Hi, IMHO it requires benchark. Also there is temptation to make StringBuilder static. See this stackoverflow question but may become memory hungry solution if someone uses this in bad way |
|
I've done some rudimentary benchmarks in https://gist.github.com/moritz/ab4e7cd01c36032e4d6b Results:
So a decent improvement in a micro benchmark while only slightly increasing code size and complexity sounds like an overall win to me. |
|
See also parrot/parrot#1123 to fix this in the parrot backend. |
Instead of using a
StringBuilder(which may need to repeatedly re-allocate its internal buffer), we allocate a character array of correct size. This improves the performance of micro-benchmarks, but the effect on setting compilation is minimal.