Posted October 05, 2022

Trooper1270
Baldrick!, do we have any milk ?...
Registered: Apr 2014
From United Kingdom

Shadowstalker16
Jaded optimist
Registered: Apr 2014
From India

rtcvb32
echo e.lolfiu_fefiipieue|tr valueof_pi [0-9]
Registered: Aug 2013
From United States
Posted October 05, 2022

Trooper1270
Baldrick!, do we have any milk ?...
Registered: Apr 2014
From United Kingdom

Magnitus
Born Idealist
Registered: Mar 2011
From Canada
Posted October 06, 2022

However, there are a couple catches:
* Some data structures, particularly those involving circular structure, require unsafe code to work, and when you use unsafe, you're throwing away the safety advantages of Rust for that bit of code.
* Safe Rust code can still leak memory, as it's been decided that leaking memory is still "safe". (Memory corruption, on the other hand, isn't considered safe.)

While there are some real-time cases that require fine-tuning of memory management, there are worlds of difference between the performance of Python and Golang.
For example, I don't think etcd (a project implemented in golang) could feasibly have been implemented in Python.

With that said, with WebAssembly it is possible to use other languages (in my current project, I use pyodide to run Python code in the web browser), but doing so can be sub-optimal, and you'll still need to have some JavaScript code in there somewhere.

Also, you are giving up the ability to execute a script as is without any extra processing that interpreted language typically have (and which is often an underestimated perk of interpreted languages btw), and yet, you gain none of the performance improvements of a true compiled language nor its possibility to run as a small self contained binary.
Also, the tooling you use to transpile is not a universal standard the way a compiler is for a compiled language and each place has their own "homemade" (ie, hot mess) setup to transpile their stuff in typescript and I've seen many a frontend tech lead spend the day to fix "their setup" because the transpilation is breaking.
In my opinion, if you are using Typescript by choice instead of a compiled language and it isn't because you are in the browser or there is a super hot library in Typescript that just makes a world of difference for the particular problem you are trying to solve, you are using an inferior alternative.
Post edited October 06, 2022 by Magnitus

dtgreene
vaccines work she/her
Registered: Jan 2010
From United States
Posted October 06, 2022

Worth noting that memory leaks can occur in garbage collected languages. It is possible for data to still be reachable, but not actually accessed that way. (For example, put every new node into a list, but never remove it from the list, even when done with it, and keep a reference to the list around somewhere.)


While there are some real-time cases that require fine-tuning of memory management, there are worlds of difference between the performance of Python and Golang.
For example, I don't think etcd (a project implemented in golang) could feasibly have been implemented in Python.
From a perspective of learning data structures, garbage collected languages are basically equivalent (unless, say, one of the languages has a fundamentally different programming paradigm, like if you throw in some Lisp dialect in there).
Post edited October 06, 2022 by dtgreene

dtgreene
vaccines work she/her
Registered: Jan 2010
From United States
Posted October 06, 2022

Bun (yet another node.js alternative) does the same.

Magnitus
Born Idealist
Registered: Mar 2011
From Canada
Posted October 06, 2022
I think that would greatly reduce the usability of the language though.
dtgreene: Worth noting that memory leaks can occur in garbage collected languages. It is possible for data to still be reachable, but not actually accessed that way. (For example, put every new node into a list, but never remove it from the list, even when done with it, and keep a reference to the list around somewhere.) Yes, exactly. That's why I'm skeptical that it is feasible to eliminate all cases of memory leaks.
I believe that would require accurate extrapolation of a programmers' intent from the code (something a human can do, but anything short of an AI can't).
dtgreene: Golang may have better performance than Python, but it still has some similar properties; in particular, worst case performance (when garbage collection occurs at a bad time) is still much worse than average performance. Hence, I still wouldn't use either language for hard real-time (for example, if failure to get something done in time would result in a crash). Well, I don't think you and I are working on the same kinds of software. I tend to work with networked software a lot, where realistically, there are milliseconds delays during network hops and things that happen within a fraction of a second are acceptable.
What I can tell you is that a store like etcd, which is written in golang, can support 10k concurrent writes per second, which is enough for the overwhelming majority of our operational use cases and to run a kubernetes cluster on (and the worst case performance for those requests are still a small fraction of a second).
Would it deliver the same throughput if it was implemented in Python? Very doubtful.
dtgreene: From a perspective of learning data structures, garbage collected languages are basically equivalent (unless, say, one of the languages has a fundamentally different programming paradigm, like if you throw in some Lisp dialect in there). If you do a lot of btree processing for a database, I guarantee you that golang will do it faster than Python.
Here are some benchmarks (the difference is quite ridiculous): https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go-python3.html
Sure, it would be even faster in rust/C/C++, but there are tradeoffs to consider:
- For many of our use cases, Golang has the better ecosystem support (ie, richer integrations with other stuff we use)
- Go is a better sell with the team, because it has a small learning curve
- Go is faster to develop in and we have deadlines
- Given the above and the fact that the difference between rust and go are not as drastic as between go and python, there are diminishing returns to consider
dtgreene: Deno (an alternative to node.js) addresses this by integrating the typescript support into the runtime.
Bun (yet another node.js alternative) does the same. Yes, that at least addresses the standardization problem (ie, one elegant universal tool to do the job), but it still transpiles to JS instead of assembly (or some bytecode better adapted to the source language) and thus the other limitations apply.
Actually, I believe the creator of Dano even expressed some regrets about making it for typescript.
Unless someone manages to make Typescript render to a lower level abstraction (ex: assembly) and then divorce the language from Javascript completely, I think it is doomed to be a passing fad (very intense one, but a fad still).
At this point, all the run times (browser engines really) have years of optimization in JS so that might take a while, if it ever happens. Should it happen, maybe I'll give it the time of day, but until then, I'd rather invest my limited time mastering better more well thought of tooling that are not a knee-jerk reaction to what a language it is based on and heavily coupled with isn't.

I believe that would require accurate extrapolation of a programmers' intent from the code (something a human can do, but anything short of an AI can't).

What I can tell you is that a store like etcd, which is written in golang, can support 10k concurrent writes per second, which is enough for the overwhelming majority of our operational use cases and to run a kubernetes cluster on (and the worst case performance for those requests are still a small fraction of a second).
Would it deliver the same throughput if it was implemented in Python? Very doubtful.

Here are some benchmarks (the difference is quite ridiculous): https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/go-python3.html
Sure, it would be even faster in rust/C/C++, but there are tradeoffs to consider:
- For many of our use cases, Golang has the better ecosystem support (ie, richer integrations with other stuff we use)
- Go is a better sell with the team, because it has a small learning curve
- Go is faster to develop in and we have deadlines
- Given the above and the fact that the difference between rust and go are not as drastic as between go and python, there are diminishing returns to consider

Bun (yet another node.js alternative) does the same.
Actually, I believe the creator of Dano even expressed some regrets about making it for typescript.
Unless someone manages to make Typescript render to a lower level abstraction (ex: assembly) and then divorce the language from Javascript completely, I think it is doomed to be a passing fad (very intense one, but a fad still).
At this point, all the run times (browser engines really) have years of optimization in JS so that might take a while, if it ever happens. Should it happen, maybe I'll give it the time of day, but until then, I'd rather invest my limited time mastering better more well thought of tooling that are not a knee-jerk reaction to what a language it is based on and heavily coupled with isn't.
Post edited October 06, 2022 by Magnitus

dtgreene
vaccines work she/her
Registered: Jan 2010
From United States
Posted October 06, 2022


What I can tell you is that a store like etcd, which is written in golang, can support 10k concurrent writes per second, which is enough for the overwhelming majority of our operational use cases and to run a kubernetes cluster on (and the worst case performance for those requests are still a small fraction of a second).
Would it deliver the same throughput if it was implemented in Python? Very doubtful.
The thing is, real-time is not the same as raw speed. In your use case, millisecond delays are expected. In a hard real-time situation, on the other hand, millisecond delays could be catastrophic.
For example, if you're generating sound and immediately playing it back, and the sound isn't being generated fast enough, the result will be audible, and it won't sound that good, even if this only happens briefly. For example if, during audio generation, a garbage collection cycle is triggered, that can cause audio to not be generated fast enough, and there will be an audible "pop" in the audio at that point, and we don't want that, particularly if you're trying to produce music. (One typical solution is for the audio code to run in its own thread, in a language with no garbage collection, and with realtime priority.)
Or, you could have software that controls safety critical hardware. A failure here could be catastrophic, resulting in property damage, or worse, loss of human lives. (Before you say that's ridiculous, look up the THERAC-25, which killed people via radiation overdose because of a software bug.) If you have a hard real-time constraint here, you can't afford *any* unpredictability here.
The important point: Real-time is not actually about speed; it's about predictability. What's important here is not that the task gets completed (on average) as fast as possible, but that it gets consistently completed in under a certain amount of time.
By the way, there is one very common soft real-time situation that comes up in many types of software, including web applications; the user interface. If the user clicks on something, and the computer doesn't respond fast enough, the user will think that it's not working. I don't remember what the actual time constraint is, but it's definitely a soft real-time constraint. (Note that it's OK if the entire action takes longer than that; it's just that the GUI needs to respond, in some way, within the time limit or the user will get frustrated.)
But Rust's performance is more predictable, and sometimes that is what you need.
Post edited October 06, 2022 by dtgreene

Magnitus
Born Idealist
Registered: Mar 2011
From Canada

dtgreene
vaccines work she/her
Registered: Jan 2010
From United States
Posted October 06, 2022


However, there are many categories of applications where reasonable differences in latencies are not an issue, but that doesn't mean that performance doesn't matter.
Online multiplayer gaming is an example of a networked soft real-time problem, assuming the game is real-time and not turn-based. If the packet doesn't reach the other player in time, it is effectively lost, as the situation is no longer relevant. Streaming of video or audio is another one. (One interesting characteristic of these problems: If it takes too long for a packet to arrive, it might as well not have been sent. Hence, the advantages of TCP (reliability and reliable ordering of packets) are not present here.) (Note that, for a turn based game like Civilization 3 or Pokemon, the situation is very different, and you don't have the real time constraint here (aside from having the UI react to player input, but that part doesn't involve the network).

WinterSnowfall
Bastard Lunatic
Registered: Apr 2012
From Romania
Posted October 06, 2022
On a side-note the reference implementation of Python is constantly being overhauled and optimized for speed. This is an ongoing focus for its creator with corporate sponsorship and involvement from Microsoft. Expect it to get a lot better in a couple of years - actually we're already seeing some major upticks because of their work.

lupineshadow
New User
Registered: Apr 2012
From Japan
Posted October 06, 2022

Then move to Rust. It's the flavour of the month.
Post edited October 06, 2022 by lupineshadow

dtgreene
vaccines work she/her
Registered: Jan 2010
From United States
Posted October 06, 2022


Then move to Rust. It's the flavour of the month.
(On Windows, segmentation faults are called general protection faults; it's what typically causes the "this program has performed an illegal operation window" dialog to pop up.)

Magnitus
Born Idealist
Registered: Mar 2011
From Canada
Posted October 06, 2022

Unless you're paying a fortune, such guarantees are hard to make over the internet.

Of course, you can have much better latency over LAN, but people don't seem to be doing that anymore.

I think it is unsuitable for intensive system stuff, but I think a lot of applications are not doing anything special that would warrant the consideration.
I mean, most of them will leverage a database that is well optimised, leverage load balancers, network meshes, kubernetes and other lower level components that need to be well optimised and those components can't be implemented in Python, but most shops don't implement things like those, they just consume them.
The high level glue that puts all of the optimised components together and solve the requirements for some high level business application? Usually, that has much looser performance requirements.
Post edited October 06, 2022 by Magnitus