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

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
Posted October 06, 2022

Some solutions like mongodb will scale well enough horizontally (assuming you are smart with your shard keys) if the nature of your queries scale well horizontally also (most tend to). Other solutions like a postgres and etcd cluster, not so much so you need to make your hardware count (and you can go a long way with those solutions even though they don't scale as well, because they are implemented efficiently).

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.

Completely agree and this is why I'm learning Rust.
Post edited October 06, 2022 by Magnitus

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