Live data from Hacker News

You Should Compile Your Python and Here’s Why

glyph.twistedmatrix.com

21–30 of 109 posts

Re: You Should Compile Your Python and Here’s Why

#22

"Python is Slow, And That's Fine, Because It's Fast Enough" At least this is honest. No matter what the script does, no matter how fast the libraries, the Python intepreter has a slow startup time. On multiple occasions I have seen people commenting on HN argue that Python is not slow. I think for these commenters Python is "fast enough". For others, like me, it may not be "fast enough". IOW, the question is not whet…

(Thinking into the wild here…) Wonder if python could be sped up by not being loaded as usual per call. Ie something more like a service with careful namespace management. I’d think something that copies what’s already in ram to new registers would be much faster.

Re: You Should Compile Your Python and Here’s Why

#23

"Python is Slow, And That's Fine, Because It's Fast Enough" At least this is honest. No matter what the script does, no matter how fast the libraries, the Python intepreter has a slow startup time. On multiple occasions I have seen people commenting on HN argue that Python is not slow. I think for these commenters Python is "fast enough". For others, like me, it may not be "fast enough". IOW, the question is not whet…

Python, while slow, is "fast enough" because it's super easy to add native objects for anything that's too slow. It's kind of an inversion for the usual scripting language layout with fast native code loading slow snippets of script to provide customization, and tbh that's probably the better approach for most situations. Write the 99% of your application that's not performance critical in something quick and easy and flexible, and then optimize the heck out of the remaining 1% that matters.

(Not a card carrying Python fan or anything, haven't used it in a decade, I just like this architecture.)

> IOW, the question is not whether Python is "fast" or "slow", but whether it is "fast enough" or "too slow" for a given user.

100% this. There isn't REALLY any such thing as good/bad/fast/slow/cheap/expensive, there's just "meets spec better" / "doesn't meet spec as well". Everything is relative to your requirements.

Re: You Should Compile Your Python and Here’s Why

#24
post #23

"Python is Slow, And That's Fine, Because It's Fast Enough" At least this is honest. No matter what the script does, no matter how fast the libraries, the Python intepreter has a slow startup time. On multiple occasions I have seen people commenting on HN argue that Python is not slow. I think for these commenters Python is "fast enough". For others, like me, it may not be "fast enough". IOW, the question is not whet…

Python, while slow, is "fast enough" because it's super easy to add native objects for anything that's too slow. It's kind of an inversion for the usual scripting language layout with fast native code loading slow snippets of script to provide customization, and tbh that's probably the better approach for most situations. Write the 99% of your application that's not performance critical in something quick and easy an…

This works well for applications where you have that kind of split, but there are applications where most of the time is spent scattered around a lot of the code - and if you are in that situation in Python and need to go faster, it's an awkward place to be.

Re: You Should Compile Your Python and Here’s Why

#25

I've been writing some python the last few days. Today I did something terrible. I like to believe it was out of wisdom rather than ignorance. I needed to do some nuanced bit manipulations, and so I built up a string of ascii 0's and 1's, sliced the string, and then converted back to integers. I worked on a codebase many years ago when I was an intern. That code would read frames off a CAN bus in a car. For some reas…

Reminds me of that Tao of Programming koan (if I remember it rightly) that went something like:

The novice, in his frustration, struck the side of his computer. The master walked over and asked what he was doing. The novice exclaimed, "my computer is not working and I do not know why!" The master admonished him, saying "you cannot solve the problem by striking the computer without knowing what is wrong." Then the master struck the side of the computer, and it worked flawlessly.

(I love this one because one time I was doing a gig and my computer refused to boot. Suspecting that the vibration from being lugged into the car and taken for a long drive had unseated something slightly, I gave it a sharp smack and power cycled it, and it started up fine.)

Re: You Should Compile Your Python and Here’s Why

#26
post #23

Earlier quoted context omitted.

Python, while slow, is "fast enough" because it's super easy to add native objects for anything that's too slow. It's kind of an inversion for the usual scripting language layout with fast native code loading slow snippets of script to provide customization, and tbh that's probably the better approach for most situations. Write the 99% of your application that's not performance critical in something quick and easy an…

This works well for applications where you have that kind of split, but there are applications where most of the time is spent scattered around a lot of the code - and if you are in that situation in Python and need to go faster, it's an awkward place to be.

Yeah, when none of the code is tight inner loops, all of it is. Not much to do then but reimplement your program in a more efficient language... then call it from a Python script. ;)

Re: You Should Compile Your Python and Here’s Why

#27
post #23

"Python is Slow, And That's Fine, Because It's Fast Enough" At least this is honest. No matter what the script does, no matter how fast the libraries, the Python intepreter has a slow startup time. On multiple occasions I have seen people commenting on HN argue that Python is not slow. I think for these commenters Python is "fast enough". For others, like me, it may not be "fast enough". IOW, the question is not whet…

Python, while slow, is "fast enough" because it's super easy to add native objects for anything that's too slow. It's kind of an inversion for the usual scripting language layout with fast native code loading slow snippets of script to provide customization, and tbh that's probably the better approach for most situations. Write the 99% of your application that's not performance critical in something quick and easy an…

I think one thing that makes many Python programs "fast enough" is that people have already provided a huge pile of native objects in the form of the OS and its trimmings. But this is true for other languages as well. If I were writing in C, I'd never try to rewrite any portion of the OS unless I had some otherwise insurmountable issue to overcome.

Quite a lot of programs are almost entirely bopping along from one OS or numpy call to the next, with a tiny bit of business logic thrown in. You've got a better chance of making your users happy by thinking about that business logic at a high level, than trying to optimize code that's only doing 1% of the actual work.

My use for compiled code is when there's no OS, and every nanosecond matters, e.g., working with microcontrollers.

Re: You Should Compile Your Python and Here’s Why

#30
post #25

I've been writing some python the last few days. Today I did something terrible. I like to believe it was out of wisdom rather than ignorance. I needed to do some nuanced bit manipulations, and so I built up a string of ascii 0's and 1's, sliced the string, and then converted back to integers. I worked on a codebase many years ago when I was an intern. That code would read frames off a CAN bus in a car. For some reas…

Reminds me of that Tao of Programming koan (if I remember it rightly) that went something like: The novice, in his frustration, struck the side of his computer. The master walked over and asked what he was doing. The novice exclaimed, "my computer is not working and I do not know why!" The master admonished him, saying "you cannot solve the problem by striking the computer without knowing what is wrong." Then the mas…

It was one of the AI koans in Jargon:

> A novice was trying to fix a broken Lisp machine by turning the power off and on.

> Knight, seeing what the student was doing, spoke sternly: “You cannot fix a machine by just power-cycling it with no understanding of what is going wrong.”

> Knight turned the machine off and on.

> The machine worked.

Post reply on HN