News for hackers. Stuff that matters.
Re:Show HN: ZFS Implementation in Python by spullara on Saturday May 04, 2019 @01:45PM (#19827976)
Faster that CPython doesn't mean it is fast.
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @04:45PM (#19829269)
I was trying to speed up a log processing service running on PyPy by rewriting it in Java. I was surprised that the result was about twice slower (I know Java quite well and I didn't see obvious optimizations; most of the time was spent in GC). So it can be quite fast even in more absolute terms (VM languages), at least for some types of code.
Re:Show HN: ZFS Implementation in Python by spullara on Saturday May 04, 2019 @05:22PM (#19829475)
If more than 1% of your time is in GC you are doing something very wrong.
Re:Show HN: ZFS Implementation in Python by michaelmrose on Saturday May 04, 2019 @06:20PM (#19829746)
The fact that a singular implementation was better than java says less about the languages and more about the particular software.
Re:Show HN: ZFS Implementation in Python by tigershark on Saturday May 04, 2019 @05:41PM (#19829557)
I know that it’s asking a lot, but any chance that you can post a minimum reproducible sample? From what I know it is quite smelly...
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @05:49PM (#19829604)
I don't have access to this codebase now but I'll try to write some benchmark.
Re:Show HN: ZFS Implementation in Python by tigershark on Saturday May 04, 2019 @05:55PM (#19829634)
If you manage to do it would be awesome, otherwise thanks a lot anyway for the effort :) I’m just curious to understand why it happens because it’s exactly the opposite of what I would expect. The only explanation that comes to my mind is excessive gc as someone else already mentioned, but it would be interesting to see the original code.
Re:Show HN: ZFS Implementation in Python by twa927 on Saturday May 04, 2019 @06:24PM (#19829765)
I started doing it but yes, it's too much effort to get two full benchmarks, I'm sorry :). But I think it went down to the inefficiency of String.split(): https://stackoverflow.com/questions/37007189/string-split-te... and generally the Java's String built-in methods not being GC-friendly: https://stackoverflow.com/questions/20336459/garbage-friendl.... I'm guessing that when such parts can be coded in a non-VM environment (CPython/PyPy runtime) they can be made much faster, and Java to these days has the standard library coded in pure Java?
Re:Show HN: ZFS Implementation in Python by tigershark on Sunday May 05, 2019 @03:40AM (#19831666)
Yes, Java has nothing like C# Span to avoid these kind of problems, but I thought that also python would be affected in a similar way... Anyway, thanks for sharing.
Re:Show HN: ZFS Implementation in Python by auscompgeek on Saturday May 04, 2019 @11:39PM (#19830990)
CPython and PyPy are both VMs, similarly to the JVM.
Re:Show HN: ZFS Implementation in Python by twa927 on Sunday May 05, 2019 @03:38AM (#19831652)
I meant the inside of a VM (its implementation), which is coded in C/RPython. Java's VM is coded in C++, but I don't think C++ is used for any regular library functions, while C is used heavily for Python's stdlib.
Re:Show HN: ZFS Implementation in Python by pjmlp on Sunday May 05, 2019 @05:11AM (#19831877)
Not all JVMs are implemented in C++.

It is a specification with multiple implementations, some of them are even bootstrapped in Java.

Re:Show HN: ZFS Implementation in Python by d0mine on Sunday May 05, 2019 @01:36AM (#19831350)
Re:Show HN: ZFS Implementation in Python by int_19h on Sunday May 05, 2019 @09:04PM (#19836112)
I had a binary parser written in Python that took around 30 seconds on typical input on CPython. PyPy took that down to about 10 seconds. Rewriting it in C# took it down to 200 ms.
Re:Show HN: ZFS Implementation in Python by twa927 on Monday May 06, 2019 @04:08AM (#19837627)
If this was using a loop processing a single byte in an iteration I would expect a greater speedup on PyPy. I've seen 100x speedup in such cases.
Re:Show HN: ZFS Implementation in Python by int_19h on Tuesday May 07, 2019 @12:26AM (#19846576)
Not single byte, but individual fields (float32/int32/string etc). Yes, I expected a much more significant speed-up as well. It's probably because a lot of that code was driven by reflection-type techniques.

Curiously, IronPython did better than anything (but still slow). Haven't tried Jython.

Compiling the whole thing with Cython was less effective than PyPy.

Re:Show HN: ZFS Implementation in Python by twa927 on Thursday May 09, 2019 @08:15AM (#19867516)
Yes, reflection voids many JIT paths in PyPy, AFAIK. Maybe it was worth rewriting the Python code to get rid of the reflection?