Live data from Hacker News

Show HN: Python can make 3M+ WebSocket keys per second

github.com

31–40 of 75 posts

Re: Show HN: Python can make 3M+ WebSocket keys per second

#31

The hardest part of debugging Python is "hitting the wall" when you come to a native library (compiled C code). And Python has achieved a lot of speed-ups from Py2 to Py3 by adding more compiled C code. This is a real blocker for understanding the foundation library. On the other hand, in Java, with a few exceptions around Swing (native painting for GUIs) in Java, almost everything is written in pure Java, so you can…

> The hardest part of debugging Python is "hitting the wall" when you come to a native library (compiled C code).

Aren’t most of these native libraries open source? I’m a C# dev so maybe this is a naive question based on my experience but is there not a way to bring in the source of the C library and debug into it in these “hit the wall” situations?

Re: Show HN: Python can make 3M+ WebSocket keys per second

#33
post #4
post #2

The title should be “optimization-demo” (original title) or “Replacing parts of Python programs by C++ can be easy and profitable”. They replace Python code that makes 5 calls into native code by code that makes 1 call that makes those 5 calls, and get a speed up from 869k calls per second to 3.15m calls per second, so a snarky title could even be “Python-to-native calls are slow”. They could even measure it by addin…

Did you take a look at the C++ implementation of the hashing function they did? I didn't see a single call made there. They replaced python code that makes 5 calls into a single call.

That's a copy-pasted variation of this public-domain SHA1 code: http://ftp.funet.fi/pub/crypt/hash/sha/sha1.c surrounded by base64 decoding and encoding for a known-length binary text.

By inlining all library code you use, yes indeed, you too can also not make a single call.

Re: Show HN: Python can make 3M+ WebSocket keys per second

#34

The hardest part of debugging Python is "hitting the wall" when you come to a native library (compiled C code). And Python has achieved a lot of speed-ups from Py2 to Py3 by adding more compiled C code. This is a real blocker for understanding the foundation library. On the other hand, in Java, with a few exceptions around Swing (native painting for GUIs) in Java, almost everything is written in pure Java, so you can…

Likewise, in C#, almost everything is written in pure C#. It also gives you more control over memory allocations than Java, which is nice when trying to squeeze more performance out of the code.

if you need speed ups like that, don't program in either.

I strongly doubt any production C# code is significantly faster than its JAVA counterpart.

Re: Show HN: Python can make 3M+ WebSocket keys per second

#36
post #6

Earlier quoted context omitted.

Do you think that relying less in C code could be better for Python and it’s community? I mean less focus on being “glue” between C code and more focus con optimizing the interpreter?

If you asked me, Python not only shouldn't rely on (third-party) C library code, but it shouldn't even be used for cases where pure Python is not optimal.

Then no one would really use Python then? It's far too slow

Re: Show HN: Python can make 3M+ WebSocket keys per second

#38
post #31

The hardest part of debugging Python is "hitting the wall" when you come to a native library (compiled C code). And Python has achieved a lot of speed-ups from Py2 to Py3 by adding more compiled C code. This is a real blocker for understanding the foundation library. On the other hand, in Java, with a few exceptions around Swing (native painting for GUIs) in Java, almost everything is written in pure Java, so you can…

> The hardest part of debugging Python is "hitting the wall" when you come to a native library (compiled C code). Aren’t most of these native libraries open source? I’m a C# dev so maybe this is a naive question based on my experience but is there not a way to bring in the source of the C library and debug into it in these “hit the wall” situations?

You can, but then you have to setup and build the libraries in debug mode. You can then debug with gdb or visual studio. It is just a lot more work than debugging pure python.

Re: Show HN: Python can make 3M+ WebSocket keys per second

#39

Earlier quoted context omitted.

Likewise, in C#, almost everything is written in pure C#. It also gives you more control over memory allocations than Java, which is nice when trying to squeeze more performance out of the code.

if you need speed ups like that, don't program in either. I strongly doubt any production C# code is significantly faster than its JAVA counterpart.

When it comes to languages you can draw up a loose hierarchy of potential performance where languages like C# and Java are vastly equivalent. Attempting to refine it any further descends into a bikeshedding farce.

Re: Show HN: Python can make 3M+ WebSocket keys per second

#40

> Show HN: Python can make 3M+ WebSocket keys per second > This article is about optimizing a tiny bit of Python code by replacing it with its C++ counterpart. So it's C++ rather than Python.

It’s cool that languages support this kind of stuff.

So if you’re writing python the employs this technique and you still want to keep the “OS agnostic” characteristic of python does that mean you’d have to compile multiple C++ binaries and check the OS to see which one to run?

Post reply on HN