this post was submitted on 26 Feb 2024
20 points (77.8% liked)

Programming

17354 readers
250 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS
 

So I want to make a new project. It will have a website and an algorithm which will handle the requests. The thing is, web development in Rust feels harder than say in Go or Python. So I thought maybe I could somehow make bindings in Rust for Go since the faster the algorithm is, the better. However, that seems to complicate stuff as well. So do you think I should just rewrite the current algorithm in Go? Is it fast enough for it to not be a noticeable difference?

Edit: Thanks for the suggestions and advice! I decided to go with Rust for the website with Axum and the algorithm as well.

top 22 comments
sorted by: hot top controversial new old
[–] bizdelnick@lemmy.ml 41 points 8 months ago (1 children)

Premature optimization is the root of all evil. Implement algorithm the easiest way possible, profile your application, determine if this implementation a bottleneck or no. If yes, try other implementations, benchmark them and find the fastest one. Note that optimized go code can be faster than non-optimal code in rust, C, assembly or any other language.

[–] thtroyer@programming.dev 3 points 8 months ago

Absolutely.

I've seen so many projects hindered by bad decisions around performance. Big things like shoehorning yourself into an architecture, language, or particular tool, but even small things like assuming the naive approach is unacceptably slow. If you never actually measure anything though, your assumptions are just assumptions.

[–] solrize@lemmy.world 32 points 8 months ago

Go is plenty fast for most things, and it is fairly simple. Rust is more interesting from a language geek perspective. I'd decide based on which of those appeals to you. I don't see good reason to combine them, though.

[–] tiredofsametab@kbin.run 21 points 8 months ago* (last edited 8 months ago)

First write it in Go, which will likely be faster unless you are quite familiar with Rust. After that, you can port some/all of it to Rust if you wish.

Edit: by 'faster' above, I mean faster to write.

[–] elvis_depresley@sh.itjust.works 20 points 8 months ago

Go with what you want to do. If you prefer writing in one language over an other, do it.

[–] SorteKanin@feddit.dk 15 points 8 months ago

web development in Rust feels harder than say in Go or Python

Have you tried? There are some very nice web frameworks for Rust, like axum.

[–] voklen@programming.dev 10 points 8 months ago

In my experience combining multiple languages usually creates more complexity and is slower than each of them individually because you need to convert the data structures of one language into those of another. Both of them are great languages and I've made web services in both so whatever one you pick will be a good choice.

As for which one to pick, although Rust is my favorite language, if you don't know it it'll take a while to learn. So for this project I'd say to go with Go because it's simpler and you really won't notice a performance difference unless you've got a huge amount of traffic.

If you have any more questions feel free to ask!

[–] xmunk@sh.itjust.works 10 points 8 months ago (3 children)

The right answer is definitely PHP.

[–] LemmyIsFantastic@lemmy.world 7 points 8 months ago

🙄 PHP is great for most things. I can't believe it's 2024 and this terrible relic from 15 years ago still persists.

[–] Zikeji@programming.dev 3 points 8 months ago

I see we have like minded bosses lol

[–] Aarkon@feddit.de 1 points 8 months ago

Cursed reply. Love it. 👌

[–] jadero@programming.dev 7 points 8 months ago (1 children)

Bluesky Social, or at least their PDS (personal data server) uses Go and their Docker package includes Caddy, a webserver written in Go.

I don't know what you're doing, but I have difficulty accepting that Go cannot meet your performance requirements.

[–] Asudox@lemmy.world 1 points 8 months ago (1 children)

The webserver performance is not my main concern. It's the speed of the algorithm.

[–] jadero@programming.dev 6 points 8 months ago

I didn't suggest otherwise. I was merely pointing at a couple of examples where some pretty smart, pretty experienced people used Go to successfully implement entire collections of algorithms in some very performance-sensitive systems. It's just by coincidence that I chose those examples because that is where my study is right now. Ask me in a year and I might point to your project as an example when the next person is asking for similar advice.

If Go isn't going to be fast enough to perform your task, then you're probably going to be sorely disappointed when you finally get the performance you're after and then have to stick it at the end of a wire with all kinds of stuff between you and your end users:

Operating systems, databases, hardware, virtual machines, containers, webservers, firewalls, routers, HTML/CSS/whatever, DNS, certificate authorities, more routers and firewalls, ISPs, modems, more routers and firewalls, WiFi connected machines of all kinds, and random browsers implementing any of several different rendering engines.

Quite frankly I can't imagine a language that won't offer enough performance to meet your needs in that environment.

[–] YIj54yALOJxEsY20eU@lemm.ee 3 points 8 months ago

Given that it's a webserver and not a constantly running algorithm, definitely Go. It's plenty fast and is much more flexible.

[–] treechicken@lemmy.world 3 points 8 months ago

My vote is Go. I've tried to make web services in both before and personally always found Go easier to use without noticeable performance trade-offs (even for real-time websocket apps). I feel you could always optimize more later if you start actually seeing performance issues.

[–] mofongo@lemm.ee 2 points 8 months ago

Yes go fast

[–] Fudoshin@feddit.uk 2 points 8 months ago (1 children)
[–] ICastFist@programming.dev 2 points 8 months ago

It's an enjoyable all purpose language, though significantly "nichier" than most niche ones

[–] wargreymon2023@sopuli.xyz 2 points 8 months ago* (last edited 8 months ago) (1 children)

This question is quite specific to Go, also specific to the algorithm you using. You should also ask on the Go mailing list, or benchmark your algo in Go and then ask on rust mailing list.

[–] Asudox@lemmy.world 4 points 8 months ago

I guess benchmarking seems to be the most reliable answer to my question.

[–] pkill@programming.dev 0 points 8 months ago

Go with the Fiber framework will probably offer you enough performance https://www.techempower.com/benchmarks/#hw=ph&test=composite&section=data-r22