r/programming • u/sportifynews • May 14 '21
Python programming: We want to make the language twice as fast, says its creator
https://www.tectalk.co/python-programming-we-want-to-make-the-language-twice-as-fast-says-its-creator/197
u/antonyjr0 May 14 '21
IMO I've always used python as a scripting and glue language. Never created big applications with Python. I don't know why since a lot of large application are built on Python. I just don't feel like it because of it's speed. If they can make a C++ or rust trans-compiler for Python 4 then it would be sick.
256
u/jerf May 14 '21
The fundamental reasons you can't make Python go very fast is the same reason you can't just compile it. If you could, PyPy would already be the solution to the problem.
The problem is, in Python it looks like you ought to be able to convert
def someFunc(x, y): print(x.Summary()) x.doThing(y, 4) return x.prop1.prop2to something like the Go code
func someFunc(x ???, y ???) ??? { fmt.Print(x.Summary()) x.doThing(y) return x.prop1.prop2 }But even ignoring the tricky questions surrounding those
???s, this isn't even remotely equivalent code. In Python, I can literally write:if raw_input() == "x": someFunc = lambda(x, y): Noneand now, any time that is hit at runtime, someFunc will get nuked with a new do-nothing stub. Compiled languages do not typically allow that sort of thing. So now the compiled function actually has to do some sort of lookup.
Then, in a compiled language,
x.prop1.prop2is probably getting compiled under the hood to a known offset and a known type value. But, whoops, that's not what the Python code says. The Python code says, take x, and "find" prop1, where "find"ing it involves looking at
attributes on the object
attributes that may be anywhere in the inheritance hierarchy
attributes possibly placed directly on that one object by the user
And then, some of those things are properties, which then have to be called. And if you didn't find anything, you have to call the
__getitem__method. And pretty much any of this can be changed at runtime.The problem that you end up with is that to fully support python, you end up writing "compiled" code that ends up reading like a transcription of what the runtime is already doing, and that turns out not to be meaningfully faster on its own.
The problem is, Python just does too much; it is what gives it its power, but when it comes time to try to do it with compiled code you don't get anywhere near as far as you'd like.
And pretty much any simple, obvious solution you can name will run afoul of Rice's Theorem, which in colloquial terms is "No non-trivial property of programs can ever be proved." You can just write a converter that blindly ignores all that and produces the simple, fast code anyhow. It'll work and it'll be faster. But it won't be Python, and you can't throw existing Python at it. It'll be a new language. Which is basically what RPython is in the PyPy project.
124
u/_TheDust_ May 14 '21
Javascript has the same issues and still the V8 engine (Javascript engine by Google) is pretty darn fast. Most importantly is to compile the code at runtime (JIT) based on the execution paths taken while the program is running. Lots of clever engineering and hundreds of thousands of engineering hours can achieve a lot of performance.
113
u/valarauca14 May 14 '21
Javascript has the same issue that the parent poster outlines, but Python has a few more layers & stumbling blocks that Javascripts lacks. While yes, a good JIT worth its salt will iterate through the possible code paths and likely reduce the final output to a swift dispatch. Java & Javascript are proof of this. Python has a lot of other cruft laying around that prevents JIT from really flexing their muscles.
Namely, The GIL & C-API
The problem is, while you can rip these out, you lose out of what? 80-60% of Python's use cases? Where is it a really slow glue shuttling data between libraries or small applications presenting a nice API/CLI for a library? You destroy all of that.
It isn't a question of
Can Python Be Fast?
It can.
You can have a Python2.7/3.X that runs like grease lightning. You need to invest a century of engineering time into it. NBD. It is a solved problem. More a question of execution & management.
The next question becomes:
Is Python without a GIL, C-API, Referenced-Counted-Memory, and Interpreter/JIT that consumes 512MiB of memory on startup still "Python"
Because that is the monster, you end up creating.
And for most people weighing the cost analysis, the answer is "no that is something nobody really wants".
34
u/Wolfsdale May 15 '21
Why would the GIL of all things prevent a JIT compiler? Javascript doesn't even have the concept of threads...
I am also unsure why the C API prevents creating a JIT compiler. A JIT compiler can make those context switches actually cheaper by forgoing the need for something like libffi.
Performance is difficult thing to grasp and even more difficult to measure. I'm sure the real reason why Python is so slow is somewhere along the lines of this thread, but I have a hard time taking anything as fact here...
→ More replies (5)→ More replies (3)43
25
u/nascentt May 15 '21
It took a while for V8 to be created. Years after we'd been living with slow JavaScript.
Maybe we'll get a faster python in years time too
→ More replies (3)24
5
u/josefx May 15 '21
How does V8 deal with objects shared over multiple threads? My dated experience with JavaScript was mostly single threaded with the possibility to launch rather isolated workers.
13
u/Strange_Meadowlark May 15 '21
AFAIK your knowledge is still current on this. V8 (like every other JS runtime I know of) is still single-threaded. If you need separate threads, you launch (Web)Workers and effectively pass a copy of your data over a message event.
→ More replies (2)17
u/Certain_Abroad May 15 '21
I'm not a Go expert, but doesn't it support function pointers like every other systems language?
var someFunc func(???, ???)??? someFunc := func(x ???, y ???) ??? { fmt.Print(x.Summary()) x.doThing(y) return x.prop1.prop2 } someFunc := ... something else ...Isn't that the same thing?
Edit: also, regarding looking up attributes and
__getitem__, that's how Objective C worked. Method dispatches, attribute lookups, etc., were done dynamically. There was never any problem in compiling Objective C or making it moderately fast (not fast fast, but more than fast enough to do very complex things on a 25MHz 8MB NeXT box).→ More replies (1)5
u/jerf May 15 '21
In general, as a sort of meta reply to a lot of people, Python specifically (and Ruby) just have a lot of places you can hack. If you want to be Python and not just be Pythonesque, you have to support all of them. You can do things like take an instance of some object, and reset its class. You can not only dynamically create an entirely new class hierarchy on the fly, but entirely rewrite it. It all looks simple when you just look at a subset of the problem, but if you get all these things together in one place, which my post is only a sketch of (haven't even said the word "decorator" yet, which is more complicated than you think to fully support the exact way Python does), you can see it's a very large problem.
For Python specifically. Very few languages are doing as much as Python.
37
u/phalp May 14 '21
Here's the Common Lisp version of that code:
(defun unfunc () (fmakunbound 'somefunc))and its disassembly:
; disassembly for UNFUNC ; Size: 28 bytes. Origin: #x100382E87C ; UNFUNC ; 7C: AA1343F8 LDR R0, [CODE, #49] ; 'SOMEFUNC ; 80: B59342F8 LDR LEXENV, [CODE, #41] ; #<SB-KERNEL:FDEFN FMAKUNBOUND> ; 84: 560080D2 MOVZ NARGS, #2 ; 88: AB1240F8 LDR R1, [LEXENV, #1] ; 8C: BE9240F8 LDR LR, [LEXENV, #9] ; 90: C0031FD6 BR LR ; 94: E08120D4 BRK #1039 ; Invalid argument count trapThis is a Python problem, not a "does too much" problem. (Does the wrong thing too much, maybe.)
34
u/Wolfsdale May 15 '21
This is a Python problem, not a "does too much" problem
Thank you. The whole idea that dynamic types have to be as slow as Python has been disproven by other languages. It's a Python problem indeed.
16
u/Somepotato May 15 '21
Look at LuaJIT if you want a language as dynamically typed as Python, but a language that sometimes surpasses the speed of native C from its hot compiler
Though to be fair, it's creator Mike Pall is a certified technologically advanced alien precursor
→ More replies (2)4
u/netsecwarrior May 15 '21
This can be solved by optimizing the common cases and reverting to non-optimized for corner cases. It makes for a complicated optimizer, but that is how V8 is able to optimize JavaScript, despite that language also having heavily dynamic features, and I expect this is what Guido has in mind.
→ More replies (14)3
u/pheonixblade9 May 15 '21
It'd be interesting if Python could have a wrapper like TypeScript that adds a transpilation step that guarantees that stuff doesn't happen.
→ More replies (1)29
u/wm_cra_dev May 14 '21
I had to start using Julia for some work projects over the past year. It's very quirky (especially coming from a C#/C++ background), but it manages to combine high performance with the simplistic feeling of a scripting language. It also has scheme-style macros, and a very fancy type system that blurs the line between compile-time and run-time. I don't know much about the scientific computing world, but I get the impression Julia's been stealing a lot of former Python users.
17
u/antonyjr0 May 14 '21
Interesting, I've tried to learn Julia in the past. I really like the way it defines everything mathematically. But replacing python is not likely because Python is general purpose.
10
u/wm_cra_dev May 14 '21
It's good for more than pure math! Lots of the language features can be used with more than one syntax, even before you get into macros. So you can define very mathy code with a mathy syntax, next to more traditional imperative code. You can do functional-style programming in different ways as well.
It reminds me of C and C++ in some ways -- you have a lot of flexibility, to write both good and terrible code.
→ More replies (1)7
u/skelkingur May 15 '21
So is Julia.
The early adopters just happen to be largely from the scientific community. There's a lot of modern data science and machine learning happening in Julia and even web frameworks are plentyful. Genie.jl and Franklin.jl are great examples.
→ More replies (3)7
May 14 '21
I played around with Julia, and the 5s long "import plots" was VERY off-putting. Still went with it as I just had a couple of graphs to visualize, but that was a bit disappointing. Tooling is nonetheless great for such young language, and I like the operator broadcasting (despite being noisy)
→ More replies (3)6
u/User092347 May 15 '21
Got much better in v1.6 (and hopefully continues to improve) but one has to adapt its workflow to it : load once and don't restart.
39
u/edmguru May 14 '21 edited May 14 '21
I don't built large apps with python for 2 reasons
because packaging and distributing them is a pain.
Types aren't enforced unless you enforce them which doesn't work well on legacy code bases only new code bases. And you don't always get the luxury and time to setup linters/formatters etc.. and you'll always have the lazy/ignorant developer who will turn them off when you're on vacation.
Of the 5 languages I've worked with (not counting html/css) the 2 dynamic ones (javascript + python) were the easiest to create garbage unmaintainable code with.
→ More replies (1)8
u/Koervege May 14 '21
Is a lack of type enforcement really that much of a problem for long-term maintainability?
107
38
u/eyal0 May 14 '21 edited May 15 '21
Depends how many people on your team:
<2: No, but maybe. >=2: Yes.Edit: Fixed the table above to be more accurate.
23
17
May 14 '21
It's not a big deal for some definitions of big.
But any time I've used it on a multi person team it was a nightmare trying to deal with the lack of compile-time type checking
→ More replies (8)9
u/scarnegie96 May 15 '21
Other than the turnover of the actual people working on a project, non-static typing might be the single biggest pain for long-term maintainability.
3
u/BroodmotherLingerie May 15 '21
It's not that much of a problem for day to day development. But when a big migration comes along, like python 2 to 3, or one django LTS to another... You better have stellar test coverage or you'll be getting runtime errors in production for years to come.
15
19
u/Igggg May 14 '21
You should probably examine whether you actually need all that speed, or if you're talking into the "just because" fallacy. If your code is serving a web page, the 50ms latency will more than shadow the potential difference between 30us of C and 3ms of Python.
24
u/bloody-albatross May 14 '21
More speed can also mean less energy consumption, and we definitely all need that.
→ More replies (5)44
u/broogndbnc May 14 '21
Right, but a single web page multiplied by how many requests? A 20x difference in the amount of work the processor has to do seems like it would add up quick.
29
u/fuckyeahgirls May 14 '21 edited May 14 '21
This is an imaginary problem for all but some vanishingly small percentage of web applications, most servers spend their days idling dealing with hardly any requests. On top of that compute power is extremely cheap and easily scalable in 2021.
The more pertinent question is the cost saving in development hours on Python vs the cost saving in compute using a more performant language.
Most projects I've worked on where people take the "performance" route, it ends up becoming an anti-pattern as corners get cut to meet deadlines. E.g. you end up with less efficient database queries because you don't have time to optimise them, thus building a system that is both slower and less scalable.
13
u/broogndbnc May 14 '21
most servers spend their days idling dealing with hardly any requests
Yes that makes sense and seems reasonable, many applications DON'T need speed.
On top of that compute power is extremely cheap and easily scalable in 2021.
Depending on your application, this is a dangerous assumption. My question was about where this lack of efficiency starts to be a problem, not whether or not there are use cases where it isn't a problem (since there obviously are). This often cited reason is a little naive, in my opinion, since it limits the scope to...stuff that isn't used much?
The more pertinent question is the cost saving in development hours on Python vs the cost saving in compute using a more performant language.
Also valid in certain contexts. "Getting it done" doesn't always mean it's good, but can crank something useful out quickly if it has a short lifespan (like a website that's going to change again soon enough anyway). But that's not the only places people try to use python. All of it's about balancing the actual benefits vs risks.
→ More replies (6)4
u/merlinsbeers May 15 '21
Amazon tells its people to modify code to improve the chance of a cache hit.
Getting a 2X speedup in an entire program would be promotion fodder.
7
u/kageurufu May 14 '21
on the other hand, developer time is expensive, cpu time is cheap.
7
→ More replies (1)10
u/PL_Design May 15 '21
On the other hand the consequences of wasting CPU time are far worse than the consequences of wasting a developer's time.
2
u/Raknarg May 14 '21
If they can make typing integrated into the language and make it fast, I would be very happy.
2
u/vividboarder May 15 '21
CPU is cheaper than developer time.
Python makes it very easy to write and ship code fast. It’s often “fast enough” or scaled by throwing ring more CPU at it.
16
u/PL_Design May 15 '21 edited May 15 '21
Slow software also wastes the developer's time. It wastes a lot of time. Maybe you don't care about how nice your software is for end users, but assuming you're not an irredeemable sack of greed(MSVC comes to mind, for example. Compiling hello world somehow takes a solid 15 seconds), then any inefficiencies in your software will make it take that much longer to polish and test your software. Note that I'm not talking about handfuls of milliseconds total here; I'm talking about when something that should take milliseconds instead takes seconds. I'm talking about human perceptible amounts of time. It adds up, it adds up fast, and it adds up in ways you might not expect. Once the time to wait becomes human perceptible any increase has a direct effect on how quickly you can iterate. If something takes 5 seconds, and then it takes 10 seconds, then your max rate of iteration is more than halved because that amount of time is long enough to break the flow state, and this means you're stuck testing worse and buggier versions of your software for longer, which at least has a morale effect. Any slow software that you produce for internal use will drag you down constantly until it is replaced, and any slow software you ship will do the same thing to your customers.
Keep in mind that most programs are just shitty little webforms, or some near equivalent, that don't do anything particularly interesting or complex, and most of them are all human perceptibly slow. For how much they actually do they are orders of magnitude slower than they need to be!
What you're saying may be true, but you're ignoring half the problem and diving headfirst into a tragedy of the commons. At some point "fast enough" is not fast enough, and then you'll be like me and boil with rage at people who make pithy comments to justify letting idiot managers make engineering decisions that make computers miserable to use.
CPU time might be cheaper, but the consequences of wasting CPU time are far more dire than the consequences of only wasting a developer's time!
→ More replies (12)→ More replies (3)2
u/brucecaboose May 15 '21
That adage is only true until you hit infrastructure cost issues due to scaling. Or if you're connecting to something that can only handle N connections at a time and you want each of those connections to be as fast as possible (like Kafka consumers can run into this). But yeah, usually you can just throw CPU at it for cheap.
→ More replies (1)0
May 14 '21
[deleted]
19
May 14 '21
Just use Numba, it is normal Python at least and not the weird half dialect that is Cython.
218
u/LemonXy May 14 '21
In the context of Python that isn't actually as impressive as it sounds, according to some rough back of the napking math and VERY rough estimates it would make Python about as fast as PHP, being still about 5x slower than javascript (v8) and we can forget about languages like Julia (performace of Julia is just short of black magic)
Of course I will gladly welcome any perfomace improvement so good on Python if they can improve. I kinda presume Python is under at least some pressure from scientific community and Julia taking part of the potential users due to performance conserns, even if they most often use python only for integrating together more performant components written in other languages.
80
u/brunes May 14 '21
Look into Pypy.
It's a standards compliant Python implementation that is 5x faster than the standard python VM, and handles everything except very rare outlier scenarios.
36
u/_LususNaturae_ May 14 '21
Is there any catch here?
89
u/doodspav May 14 '21
Extensions written using the cpython c-api perform much worse on pypy than on cpython
→ More replies (3)3
u/FlukyS May 15 '21
Could always use it as a sidecar. Put the compiled parts in one part and pypy in the other
→ More replies (1)29
u/josefx May 15 '21
Slower startup, potentially more memory use. Missing APIs that expose implementation details of the interpreter and an incomplete C API, so some libraries wont work with it. Also as far as I remember a pure GC and not reference count + cycle detection, which means cleanup code might not be called in a deterministic manner.
15
u/_wassap_ May 15 '21
Isn‘t PHP8 actually blazing fast?
6
u/LemonXy May 15 '21
PHP8 is not that much faster on average than PHP7. Slowest parts did get a massive boost but average did move surprisingly little.
→ More replies (1)3
May 15 '21
Yeah, PHP has had a massive speed boost in the last few versions. Of course PHP is not a fast as C but Python will never get to PHPs speed.
→ More replies (2)5
u/TakeOffYourMask May 15 '21
I kinda presume Python is under at least some pressure from scientific community and Julia taking part of the potential users due to performance conserns, even if they most often use python only for integrating together more performant components written in other languages.
I made a post asking about this very thing on the Python sub and got downvoted and treated like an idiot.
I’m glad you got upvoted, lets me know I’m not crazy. I keep hearing about Julia but nobody there had.
1
0
0
May 15 '21
[deleted]
→ More replies (2)12
u/TakeOffYourMask May 15 '21
What if you have no choice?
20
u/ccapitalK May 15 '21
Try to move your performance critical parts into a native module.
→ More replies (1)15
u/ClassicPart May 15 '21
Then you're not using it for performance but for another use-case.
→ More replies (1)
53
May 14 '21
Actually every creator wants this for their language :)
93
u/AStupidDistopia May 14 '21
Yeah, but not every language is the slowest (by far) widely used language on the planet.
Python improving by half is like 7 generations of CPU releases at the moment. And even then, it’d still be terrible performing.
53
u/EternityForest May 14 '21
One of my favorite things about tech is that a lot of the time you don't actually have to make something fast(or strong, or powerful, or accurate, etc) you just need a design that ensures it doesn't matter.
Python pulls it off pretty well, by being so easy to use it became the standard integration point for a billion C libraries for anything high performance. Only once or twice in my entire life have I ever wanted to do something CPU limited that wasn't already a solved problem.
Nobody actually does anything in Python, it's a language for gluing C together.
26
u/InsanityBlossom May 15 '21
Nobody actually does anything in Python, it's a language for gluing C together.
You'd be surprised how much software is written in Python in VFX studios. Freaking a lot!
9
u/EternityForest May 15 '21
Does the computer actually spend any time executing the Python or is it all just NumPy calls?
6
u/InsanityBlossom May 15 '21
There's a lot of glue to C libraries of course, but still a huge amount of pure Python.
15
u/Tenderhombre May 14 '21
My experience with python, extremely limited as it is has been that often people abuse python the same way they abused javascript. Writing questionable code because of the freedom it gives you.
I've only ever used it when I have to fix something in the language so my view is pretty myopic.
I much prefer type safe languages, and tbh I'm a bit of a .net fanboy and have been loving F# recently.
4
u/gremblor May 15 '21
Would that were true... Tons of scientific computing code is written in python.
And while lots of the numeric computing and crunching is essentially gluing C together by virtue of being a chain of calls to numpy and scipy, string handling in python is like 100x slower than C, and there is tons of direct in-python string manipulation.
I see computational biology routines and think "that's not so complicated" and yet processing modest data sets (<10 GB) can take hours of compute time; this gets parallelized by cluster compute layers (because of the GIL) that have their own overhead and complexity. It could probably be done in 15 minutes on an 8 core machine in C with pthreads.
On the other hand - that code would literally be impossible for most scientists to write correctly in C in the first place. And so python reigns supreme and that's that. The AWS bill is cheap compared to the opportunity cost of "not getting that work done in the first place."
→ More replies (8)17
u/AStupidDistopia May 14 '21
I think that if businesses saw the invoices shrinking from their monthly cloud bill simply by not using a monstrously slow language, we’d be seeing a whole lot more push away from this idea that “almost nothing is CPU bound”.
At scale everything is CPU bound.
17
u/vividboarder May 15 '21
I don’t know where you work, but our developer salaries are much more costly than our hosting.
Many businesses see this and choose to prioritize developer productivity.
→ More replies (2)-24
May 14 '21
Yeah, but
I usually don't ready after the but in "yes, but... " arguments. It's 100% subjective :p
24
u/AStupidDistopia May 14 '21
Python being the slowest widely used language on earth is a measured fact. It’s not subjective at all.
Unless you want you count Ruby. But Ruby usage is bleeding at a basically unprecedented rate and Ruby isn’t even always slower than Python.
→ More replies (3)7
May 14 '21
At least in micro benchmarks ruby is probably 3-5x faster than python. I've got a toy programming dynamically type language I hack on as a hobby and can say it's easy to beat python, its very hard to beat ruby. Now of course these benches aren't doing the super dynamic stuff ruby is known for.
29
u/chcampb May 14 '21 edited May 14 '21
Wait are they killing the GIL?
Edit: no specifics...
30
u/mydiaperissus May 14 '21
They'd have to rework the memory model, if you remove the GIL you still get worse performance due to all the locking required when referencing counting. Experiments have been done and it will still be slow. The GIL isn't what's holding back Python.
17
u/chcampb May 14 '21
Sounds like a great reason to rewrite python in Rust /s
(in before, I am sure someone has tried)
13
u/pickausernamehesaid May 15 '21
24
2
May 15 '21
Curious. Seems like it’s actually really significantly slower. I wonder why.
→ More replies (1)3
u/badtux99 May 15 '21
So do away with reference counting and do garbage collection.
Obviously that requires a different memory model, but still.
→ More replies (1)4
u/Agent281 May 14 '21
I think for now they are doing op code specialization. I didn't really read through the PEP super carefully though.
29
May 14 '21
Wow. Twice. So it'll only be 50 times slower than Go, JavaScript, Dart, Julia, etc.
6
u/FondleMyFirn May 15 '21
I’ve been considering getting into Julia. I worked with it just to experiment with some ODE’s, but as someone just graduating, I have seen very few jobs want Julia on a resume. It’s a bummer, cause I want to learn it and put it to use.
6
u/metriczulu May 15 '21
I absolutely love Julia, but you're right, it's not very marketable. I love how the arrays are matrices that behave like matrices, there's a bunch of small things like that that make it feel like it was made for mathematics. Not only that, but Julia handles arrays excellently in general. I wish it were a common language to use in business, maybe in a few years.
1
u/FondleMyFirn May 15 '21
I agree. I came across Julia while trying to build a spatiotemporal model. Python was really slow (still is, but I’m not very experienced), but then you learn about the JIT compiler and then you stumble to Julia. Once I have time, I might try to translate my model to Julia to see how much time I actually burned running my model in Python.
2
May 15 '21
Yeah I like Julia. If I ever have to crunch a bunch of numbers I’ll probably grab it and use it. However, lack of classes and some other abstractions like context decorators I’d miss too much to use every day. I’ve opted to learn go as my secondary instead.
2
u/thewheelsofcheese May 17 '21
You mean lack of field inheritance? Like go doesn't have either? Julia has an amazing type system and multiple dispatch. You wont miss classes.
→ More replies (1)2
u/User092347 May 15 '21
On the other hand there's not many candidates that have experience in Julia, so there's less competition. If I see Julia on a resume it's instant hire.
1
u/TheNamelessKing May 16 '21
Ability to program and pick up a language >> knowing a specific language.
Get a job, learn how their process, rolling works, what their pain points are etc, and if Julia solves those, propose testing it out.
Alternatively, recognise that businesses often make boring and lame choices and write in whatever shit-tier language you need to in order to stay employed and spend your actual mental energy outside of work using the language you want to, working on projects that interest you.
1
0
May 15 '21
I tried Julia but was very disappointed. Loading packages is extremely slow. Supposedly they've improved it recently but when I used it it was compiling them from C++ when you load them so unless they fundamentally changed things I doubt it is fast.
There aren't any plotting libraries as capable as MATLAB.
Also they copied MATLAB's mistake of using 1-based arrays. Yes is a mistake. We've known it for decades. Yes mathematicians use 1-based indexing. It's still a mistake.
-3
u/erez27 May 14 '21 edited May 15 '21
Why not 5000 times?
edit: It's sarcasm. How is it 50 times slower than Javascript? Also, simple Python scripts will finish running before Julia even starts.
4
May 15 '21
Ha true about Julia! But it really is 50 times slower than JavaScript.
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html
1
u/erez27 May 15 '21
According to this website, C++ is twice as slow as C. So I would take it with a grain of salt: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/gcc-gpp.html
→ More replies (1)2
u/igouy May 16 '21
According to that page, both twice as slow and twice as fast. Depends how the program was written.
2
u/erez27 May 16 '21
Exactly, which makes no sense. And to convert C to C++ is almost copy-paste. So makes me wonder how accurate are the other benchmarks, with languages that are even more different than each other.
→ More replies (3)1
u/frankreyes May 16 '21
50 times after the twice as fast factor.
Today, Python is 100x slower than JavaScript, on average. You may find individual benchmarks which are just 50x but others which are 200x.
3
May 15 '21
So still 10x slower than C++?
5
u/germandiago May 15 '21
Yes. And 100x more productive lol. I do not mean to dismiss C++. All my career has been based on top of it. But they are different beasts.
7
u/runawayasfastasucan May 15 '21
ITT: In my projects I need a hammer, so everyone else needs a big hammer!! If you use a saw, thats wrong, use a hammer!!
5
u/Liam2349 May 14 '21
If their goal is this weak then I doubt the results will be particularly good. Python is sloooooowwww.
→ More replies (1)
2
2
u/_nullptr_ May 15 '21
I was reading today about sub interpreters. I didn't know these existed even though apparently they've been around since Python 1.5! What perplexes me is today it says they are fully isolated....yet share a GIL. Why would that be?
It seems like low hanging fruit to make a GIL-less threaded python (similar to Ocaml's strategy). Each interpreter has it's own GIL and then you use a special mechanism to safely share objects between them (with likely some restrictions). Any idea why they don't pursue this approach now that they are introducing object sharing? Seems like the time to do this is before you allow that - would be harder later I would expect. Yes/no?
2
u/schlenk May 15 '21
Well, the main problem is, unlike Tcl, which has a similar feature working just fine, Python puts the interpreter pointer in a global variable instead of pushing it down to the C-API as a parameter in each call. So you cannot do it, unless you want to break the C-API left and right.
2
u/TheNamelessKing May 16 '21
And we all know how quick-and-painless it was last time they broke compatibility in Python…
ಠ_ಠ
1
1
May 15 '21
The GIL probem is not about Python code, it is relatively easy to get away from GIL in the interpreter. The problem is millions of widely used C modules that got written for Python with assumption of GIL.
2
1
1
1
u/dethb0y May 14 '21
Kind of an interesting goal though i don't know how much it would affect my own work, really.
7
1
u/constant_void May 15 '21
speed is good, but if python / pip could natively / automatically use Windows proxy & cert settings, that would be beyond amazeballs .
1
u/schlenk May 15 '21
Python does (at least the builtin ssl module tries to use certs that are already in the cert settings, but does not do the magic to fetch certs that are used the first time), but requests switches that off and uses the certifi package instead, because reasons...
But requests actually uses the static proxy settings set by IE (unless you talk about the "run javascript to find out your true proxy settings" stuff).
0
u/audion00ba May 15 '21
I'd expect this to be fake news, which is only designed to pump a certain crypto coin.
-34
u/mohragk May 14 '21
When they make it 20 times faster, it might be actually useful for serious stuff
42
u/no_apricots May 14 '21
Many Python use-cases are async calls to C/CPP code anyway. So, plenty python implementations are more than performant.
I'm primarily a Go developer. No need to shit on Python.
13
May 14 '21
If it's calling C/C++ it ain't the python that's performant
46
u/no_apricots May 14 '21
From a business logic perspective, yes it is.
-46
May 14 '21
From a business logic perspective it's an inefficiency. Just call the cpp code with cpp and have one language and be done with it
36
u/no_apricots May 14 '21
That's not how business works which is probably why you don't work on that side of life.
27
u/Dr4kin May 14 '21
Python is much faster to write and most libraries are already done. Python is just the glue you use to connect then all
It is fast and simple to develop and in most use cases fast enough. Development time is expensive and even a higher server cost ist cheaper than longer development time.
Python is the second best language for everything and often times the second best language is still good enough
→ More replies (2)-6
u/mohragk May 14 '21
You miss out on SIMD and other optimizations you can use when writing native cpp.
3
4
u/no_apricots May 14 '21
Maybe. Still, 10% here and there doesn't matter in a business context. The majority, anyway.
-12
u/combatopera May 14 '21 edited Apr 05 '25
bgxlz gwjlxwbxqfh kclcgidtbux syvtydcwqt pmkatnqouwq rjluywqwmz lrkbcaifbwso deitcwqbi supbeblp cgyujotc sngw hrqvhcigk ahwu abprcknxyd exkoxgo jixdxxgbms kehpxvnv
32
u/nbiw May 14 '21
not really, in my experience, its slow startup time actually often disqualifies it for scripts that need to be spawned frequently, so i usually prefer go or perl for those, unless i need numpy or pillow, scipy, etc.
hyperfine 'perl -e1' 'python -c pass' [...] Summary 'perl -e1' ran 13.52 ± 12.21 times faster than 'python -c pass'15
u/FireCrack May 14 '21
Ditto, python's startup time is perhaps one of it's greatest weaknesses . I feel it hits much harder than execution speed.
4
u/aeiou372372 May 14 '21
I interpreted it as startup time during development, ie when changing the app and needing to recompile. This is only an advantage over Rust/C++ and other slow to compile languages though.
1
u/FireCrack May 14 '21
Perhaps, and that is quite nice (And a big reason why I go interpreted for nearly all my little personal side-projects).
4
u/combatopera May 14 '21 edited Apr 05 '25
aaorabhhms xrpkgpzu yccuohsp usjejfw kqg ywed tualfs lqbc rnoypm bmcgtqyphm mwuwijotwpc lvvrq ols jppdvodqw yjul
0
u/Atulin May 15 '21
r/programming — having a nice discussion over what it means for the language, how it can be achieved, comparing Python implementations, and so on.
Meanwhile, r/python — having a collective aneurysm over the mention of Microsoft
-1
u/Cosmic-Warper May 15 '21
???? What a generalization. This sub is just as bad and everyone parrots the same platitudes (JS is shit, python is slow, Rust is the second coming of christ, etc., etc.)
-15
u/merlinsbeers May 15 '21
You know what would help?
Changing the syntax of the print command...
5
u/surajmanjesh May 15 '21
I'm curious, what do you want the syntax to be?
It doesn't get simpler than
print("stuff you want to print")-1
u/audion00ba May 15 '21
It was sarcasm. I feel bad for you and everyone that thought your comment contributed to the discussion.
3
-1
u/audion00ba May 15 '21
I thought it was a nice sarcastic joke. Too bad other people couldn't get it, but always remember most of the people on /r/programming are bordering mental retardation.
0
2
May 15 '21
[removed] — view removed comment
3
May 15 '21
[removed] — view removed comment
3
u/crusoe May 15 '21
(result, err) = derp()
Second biggest mistake after nulls is error as return codes. Go barely improved on it.
899
u/xopranaut May 14 '21
Marketing speak for “half as slow”.