Tik Tok saved $300000 per year in computing costs by having an intern partially rewrite a microservice in Rust.
Posted by InfinitesimaInfinity@reddit | programming | View on Reddit | 448 comments
Nowadays, many developers claim that optimization is pointless because computers are fast, and developer time is expensive. While that may be true, optimization is not always pointless. Running server farms can be expensive, as well.
Go is not a super slow language. However, after profiling, an intern at TikTok rewrote part of a single CPU-bound micro-service from Go into Rust, and it offered a drop from 78.3% CPU usage to 52% CPU usage. It dropped memory usage from 7.4% to 2.07%, and it dropped p99 latency from 19.87ms to 4.79ms. In addition, the rewrite enabled the micro-service to handle twice the traffic.
The saved money comes from the reduced costs from needing fewer vCPU cores running. While this may seem like an insignificant savings for a company of TikTok's scale, it was only a partial rewrite of a single micro-service, and the work was done by an intern.
TadpoleNo1549@reddit
yeah “optimization doesn’t matter” is one of those takes that only works until scale hits, this is a perfect example of where it actually matters, cpu bound plus high traffic = real money, also crazy that an intern pulled that off, feels like the real takeaway is optimize where it counts, not everywhere
Daffodil_Software@reddit
Nice post, really nails why performance optimization still matters, especially when you run services at scale. That anecdote about the rewrite from Go → Rust is a textbook example of how even “fast enough” languages and frameworks can hide huge inefficiencies under load.
Daffodil_Software@reddit
If you’re starting fresh, you can keep things lightweight and still cover all the bases without pulling in big frameworks.
Playwright is still the best choice for E2E, and it now has built-in visual regression via toHaveScreenshot(), so you don’t need extra tooling. For smaller visual diff needs, pixelmatch or reg-suit are great tiny add-ons.
For component/unit tests, React Testing Library + user-event is still solid. Add MSW for network mocking, it’s probably the single biggest quality-of-life improvement for test reliability
Daffodil_Software@reddit
If you’re starting fresh, you can keep things lightweight and still cover all the bases without pulling in big frameworks.
Playwright is still the best choice for E2E, and it now has built-in visual regression via toHaveScreenshot(), so you don’t need extra tooling. For smaller visual diff needs, pixelmatch or reg-suit are great tiny add-ons.
For component/unit tests, React Testing Library + user-event is still solid. Add MSW for network mocking, it’s probably the single biggest quality-of-life improvement for test reliability
manuthlochana@reddit
This is EXACTLY why Rust is taking over! 🚀 An INTERN saved $300K/year - imagine what a full team could do. The performance gains are insane: 78% to 52% CPU usage, latency cut by 4x! This is the future of systems programming. Companies sleeping on Rust are literally burning money.
UpstairsKnown372@reddit
They will save more money if they switch to Go
byteNinja10@reddit
This is really impressive. Shows how performance optimization can have a direct impact on costs. The fact that an intern was able to do this is even more interesting - it means the ROI on choosing the right language for the right task can be huge. Would love to see more companies being transparent about these kinds of wins.
WiseWhysTech@reddit
Hot take: “Don’t optimize” is lazy advice. Optimize after profiling.
Why this TikTok story matters: It shows the trifecta—lower CPU, lower memory, lower p99—and 2× throughput. That’s real money saved at scale.
What to do in practice: 1. Profile first: flamegraphs, pprof, tracing → find the top 5% hotspots. 2. Tighten the algorithm: data structures, batching, cache-aware layouts, fewer allocations. 3. Surgical rewrites: keep 95% in Go; rewrite only the hot path (FFI/gRPC) in Rust/C if it pays back. 4. Guardrails: prove gains with A/B, load tests, p50/p95/p99, cost per request. 5. Reinvest wins: fewer cores → smaller bills → headroom for features.
Bottom line: Performance is a product feature. Measure → fix hotspots → ship.
Hax0r778@reddit
These numbers don't seem to add up... was traffic not limited by CPU or memory? How does dropping the CPU by 33% allow doubling the traffic?
Hopeful_Lettuce9169@reddit
I can answer this. It's because the physical strain above 70% is actually much worse and not linear. It's being utilized 70% and the cache is being split.
50% is absolutely night and day for utilization.
Weary-Hotel-9739@reddit
Probably garbage collection vs non. While average loads may only be 33% better, peak bursts lead to more-than-average GC, which doesn't occur under Rust. Sadly, average numbers are really bad for showing this, but come on, this is LinkedIn.
MasterLJ@reddit
Our compensation compared to our ROI to a business can vary WIIIILLLLDLY.
I had a coworker that saved \~$160M over 3ish years by optimizing some ML models (that dictated pricing).
A friend of mine works for a company that won't let him do optimizations to trim their $12M/month cloud bill because they are minting money off new features.
This is a really cool story for the intern but the ROI isn't crazy by any stretch. A $50k/year intern has HR, payroll, facilities and equipment costs (\~$100k total)... and unless there are already Rust experts at TikTok (which I'm guessing not because the intern did this), TikTok just gained exposure to a new tech stack; security, updates, compliance, maintenance, that could conceivably negate the savings.
Hopeful_Lettuce9169@reddit
I empowered something like +$300m in revenue once, and made less than 300k lol
Weary-Hotel-9739@reddit
Sorry, but you assume that employees are the limiting factors. We're currently on a declining job market. If you can send any employee - especially interns - on a month-long trip that at least covers their cost, it's already good enough for that employee and their manager.
The alternative is often not not hiring someone to do this, but to have engineers doing nothing, or useless tasks to keep them busy enough. Especially the good ones, after all, they might get offers from the competition even with overall jobs down. So to speak, they're free labor.
MTGGradeAdviceNeeded@reddit
+1 unless rust was used already at tiktok / planned to be largely rolled out, then i’d go even further and say it sounds like a business loss to have that new stack and need to maintain it
Full-Spectral@reddit
But of course by that argument we'd all still be writing Fortran or Pascal. Every company that has a Go or Rust or whatever code base to start from having no Go or Rust or whatever.
JShelbyJ@reddit
Rust is used at every major tech company to some degree, and TikTok is no exception.
Voidrith@reddit
unless its used as a stepping stone to broader adoption - the first time using a new stack is always the most expensive and complicated, but once its in the org its generally much easier/faster/cheaper to use in the future
if they can get comparable gains by redoing other problem services, then that can also make it easier to save more in the future
cute_polarbear@reddit
Yeah. Different organizations, different industries, teams, and etc. , have wildly different priorities.
hasdata_com@reddit
Watch the intern get a $500 bonus and their manager get a $50k bonus for "leadership"
alphapussycat@reddit
The intern is an intern, no pay, maybe a "nice job, I'm sure you'll get hired soon enough".
probablyabot45@reddit
Nah tiktok isn't owned by America just yet.
KrispyKreme725@reddit
I bet the intern wasn’t even offered a full time gig.
pdpi@reddit
The key word here is "scale". One of the major challenges with scaling a company is recognizing that you're transitioning from "servers are cheaper than developers" to "developers are cheaper than servers", and then navigating that transition. The transition is made extra tricky because you have three stages:
A certain type of engineer (e.g. yours truly) would rather focus on that performance work, and gets really frustrated with that second step, but it's objectively a bad choice.
Mundamala@reddit
I think the key word here is intern. This person likely never got any credit or near the pay they should have received. Even on a frontpage post remarking on their achievement, they're 'an intern.'
Pleasant_Guidance_59@reddit
The intern was embedded into a larger engineering team. It's not like they heroically discovered the potential, rewrote the entire thing on their own and shipped it without more senior engineering involvement. More likely it was a senior engineer who suggested this as their internship project, and the intern was assigned to rebuild the service with oversight of the senior engineer. Kudos for going a great job of course, but they likely can't really take credit for the idea or even the outcome. What they do get is a great story, a strong reference on their resume and proven experience, all of which will help them land a good job in the end.
Bakoro@reddit
From my own experience, it's entirely possible that the person really just is that good, or the original code was that bad.
I've been in that position, it's not even that the original person was a bad developer, they were just working outside their scope and made something "good enough", while me fresh out of college had the right mix of domain knowledge to make a much better thing.
Then there was stuff that was just spaghetti and simply following basic good development practices took the software from near daily crashes, to monthly, and then eventually zero instability.
This, at a multi-million multi-national company that works with some of the most valuable companies in the world.
Weary-Hotel-9739@reddit
Again, we're talking about an intern. For a company that actually wants to make money and survive for longer than a month. I get what you mean, but optimizing any program is incredibly easy. Not breaking everything with your optimization is hard.
If you're hired as a consultant or similar, the worst that can happen is that your contract will not be renewed. That gives you some freedom. As an intern, you're gone, and potentially the whole team too.
It's just that people fresh out of college often times really don't have nearly enough domain knowledge that they know how much domain knowledge is missing.
Bakoro@reddit
Intern status is immaterial. What we are really talking about is an unusual event noteworthy enough to get reported on, at a global organization of such scale that even small optimizations can mean six figure dollar amounts.
The above person was saying that it's entirely unlikely that the intern was actually the prime mover for the change and shouldn't really get credit, and I'm saying that it's entirely possible that it was the right person in the right place, who had the right mix of knowledge to identify and make the change, and they should absolutely get credit for the improvements they made, because a different person in the exact same position wouldn't have had the same success.
And again, I know because I've been there, I've been the person to walk in out of nowhere and solve the problems that more experienced developers couldn't solve, because I had the right perspective and the right knowledge for those problems. If I had gone to a different company then I would have been a middle tier nobody, but instead I happened to find a place that needed my exact skill set.
Weary-Hotel-9739@reddit
I've been on both sides of this, and recently, I'm really afraid of this stance.
Optimization and even six figure savings in mid sized companies is incredibly easy to do. It's hard to do without loss. I once had a consultant from a pretty famous larger agency 'optimizing' a workflow some years ago. He literally deleted both the validation and the transaction management to get speed ups. Was that good? Bad? Depends. But Dunning Kruger is a thing. If you know nothing about the context, optimizing without breaking context to your knowledge is pretty easy. Especially if you're not there long enough to ever learn the truth.
On the other hand, I was in your shoes too once. I was good at programming but I didn't know the difference to 'developing' yet. Of course, 80% of the time I still delivered great work. But the question is: is 80% acceptable? Again, it depends.
I find it highly unlikely that an intern actually has the time to analyze a billion dollar system, and reimplement full capabilities of a subsystem without loss of context. Maybe he was necessary as a piece of the solution. Maybe he even is a genius and really did it all by himself. But most likely, someone gave him a task because he had used Rust before, and enabled him with documentation and political coverage. They gave him the tools to do a task that was mostly coding.
Because, and that is reaaaally important: if you're a multi-billion dollar company that is part of an international conflict between two superpowers, you don't let your intern deploy untested code to prod, even if he is a genius. Hell, he might be an idiot - or worse, an attacker.
leros@reddit
That's just how jobs work. You agree to do work for some fixed fee (hourly rate or salary). You get that pay regardless of your performance. You can generate 0 value or tons of value or even hurt the company and you still get paid. Low risk, low reward.
If you want pay to be tied to your performance, become an entrepreneur. It's higher risk but potentially higher reward.
It's also hard in big companies to tie any result to a single person. I've built products/features that have generated tens of millions of dollars in revenue. But that happened in an ecosystem of all the other work being done in the company, so the value I generated really needs credit distributed over a lot of people indirectly involved like marketing, operations, and developers who build other parts of the system.
Weary-Hotel-9739@reddit
Completely true, but this is the reasons why companies suck at some point. From a cost-benefit standpoint, doing the least amount of useful work is best for every employee, and if upper management does not compensate, you'll not even get what you were paying for in the first place. Meanwhile productivity should actually go up over time, so you're loosing double.
Makes you wonder about FAANG.
leros@reddit
Big companies are generally not efficient anyway. The bigger you get, the more effort goes into communication rather than direct output so ICs aren't producing that much. Plus competent people tend to get pushed up into management.
Superg0id@reddit
And this is late stage capitalism to a T.
I can't pay my rent in "exposure" guys... especially as I've exposed that "as an intern, I accepted being paid jack sh!t, in order to maybe get lowballed for another job in the future"... but I'm stuck doing this since noone will pay me what I'm worth..
caltheon@reddit
you act like having proven track records on your resume doesn't offer any value, which is only true if you lie on your resume.
Superg0id@reddit
ha. Sure, put it in your resume.
But that doesn't feed you now.
Meanwhile the company "saves" that money, and what do they do?
Executive bonus for the person who came up with the "intern" idea..
maxintos@reddit
You think the intern was doing some hero work on his own time on top of the normal duties he was given?
Usually it's the senior employees that decide what the intern is going to work on and does a lot of support.
The intern being given this work probably means that the senior devs already had a good grasp of what was supposed to be done and guided the intern.
haruku63@reddit
A student I know worked as an intern for a big company and the project was very successful. His manager couldn’t raise his pay as it was fixed for interns. So he told him to just write down double the amount of hours he was actually working.
pqu@reddit
Aka timesheet fraud, nice. Hope he got that in writing, lol
CherryLongjump1989@reddit
Nah this is fine. Timesheet fraud would be if the timesheets were being used for billing or external reporting. But with a manager's authorization for an internal employee it is a nothing burger.
haruku63@reddit
He got
Mundamala@reddit
He was the first scapegoat when the company got caught insider trading.
AlexKazumi@reddit
Rofl, I was in a similar position when I was a people manager. After days of negotiation with the HRs, they proposed to gave the extra money as very specific kind of bonus (which made both the internal company systems and the government's tax agency happy).
These cases are rare, so no surprise there is no process. But definitely there is no need to lie.
ungoogleable@reddit
The intern's name is Wu Xiaoyun.
https://wxiaoyun.com/blog/rust-rewrite-case-study/
DroppedLoSeR@reddit
That second scenario becomes crucial to tackle earlier rather than later (in SAAS) if there are plans to onboard or keep big customers. Not ideal letting poorly maintained code be the reason for churn, or a new customer to cost more than they are paying because someone didn't look at the data and anticipate the very predictable future...
syklemil@reddit
Plus you need people who are actually able to focus on performance, including being familiar with relevant technologies. If the company only starts looking for them or training them in stage three, they're behind.
pinkjello@reddit
I’m not sure I agree. There have been times at work where we identify a bottleneck, investigate, do a spike to research solutions, find one, then implement. Sure, it takes longer than if the team were already familiar with the solution, but it’s not insurmountable. You stand up a POC, then refine it.
syklemil@reddit
But it does sound like you're familiar with the technologies you'd use to resolve performance issues? Not everyone is good at finding performance issues, or tell the difference between various kinds of performance issues, or know how to resolve them, which can result in a lot of voodoo "optimization".
As in, we have metrics for p50, p95 and p99 latencies for various apps, but I'm not entirely sure all the developers know what those numbers mean. Plenty of apps also run with incredible amounts of vertical headroom, with some of the reasons seeming to be stuff like :shrug: and "I got an OOM once".
caltheon@reddit
The point is you don't need know how to fix it to bring in experts that do know how, you only need to identify it, and even that can be done by a competent performance engineer pretty quickly as long as you have basic observability. You can't afford to have performance focused engineering until you hit step #3, and it isn't necessary. Having double skilled engineers is obviously best case scenario, but like most unicorn scenarios, it's not something you can guarantee.
pinkjello@reddit
Exactly. Having specialized experts on hand for when something may inevitably will arise isn’t cost effective. Better to have smart, adaptable people on hand who know how to identify a problem, learn what they need to learn to fix it, and consult an expert if that isn’t good enough, or it’s pervasive enough of a problem to shell out for top tier expertise.
pdpi@reddit
That's just your average VC-funded Tuesday!
cgriff32@reddit
Takes money to make money. Or for VC backed companies, take money to make money.
wgrata@reddit
The thing that makes this transition hard in my opinion is overcoming organisational momentum and staffing issues.
I haven't met many swes that will happily make the change or PMs, who frequently get reviewed based on feature launches, to get shift their mindset and skill set.
SanityInAnarchy@reddit
It's also worth mentioning that even when the company achieves that scale, it's not every line of code everywhere, and even the stuff that "scales" may not actually be recoverable.
Take stuff running on a dev machine to build that very-optimized microservice. If the build used to take an hour and now it takes a minute, that's important! But if it used to take a second and now it takes 1ms, does that really change much? Maybe you can come up with some impressive numbers multiplying this by enough developers, but my laptop's CPU is idle most of the time anyway.
Jaded_Ad9605@reddit
There is of course a xkcd for it...
https://xkcd.com/1205/
CherryLongjump1989@reddit
They've been saying this at least since the 90's.
singron@reddit
I think (2) is actually pretty rare. We assume that our work leads to increased revenue, but if it was that easy, every company would be wildly successful. Most of the time, product improvements have no effect on revenue, so I think you need to heavily discount that effort too. Cost saving work is usually very low risk in that it's very likely to actually lower costs.
Kissaki0@reddit
If we scope a bit wider than just direct monetary investment vs gain, investing in that analysis and change can have various positive side effects. Familiarity with the system, unrelated findings, improved performance leading to better UX or better maintainability X, a good feeling for the developer (which makes them more interested and invested), etc. Findings and change can also, at times, prevent issues from occurring later, whether soon or more distant.
It's definitely something to balance against primary revenue drivers and necessities, but I wouldn't want to be too narrowly focused onto those streams.
sopunny@reddit
To give a little more perspective, 300000 a year is about what it costs to keep a junior engineer (their total comp, plus taxes, marginal support staff costs). So if the extra performance requires an extra engineer to maintain, you're not even saving anything long-term
Mognakor@reddit
The old system also needed to be maintained so thats not really relevant, and given it is something an intern could rewrite and "only" saves 300k you're not putting an entire engineer up for maintenance.
luctus_lupus@reddit
300k for junior in this job climate? Hahahahahah
Sparaucchio@reddit
In my country they cost 600 euros per month gross, so we can make it 1000 including the support they (do not) receive from colleagues
Jaded-Committee7543@reddit
thanks for sharing, this is the kind of insight that i read reddit for !
coderemover@reddit
If you start optimizing when the server bills are higher than you pay for your developers, you're likely already doing it too late. Getting decent performance after the system is fully in production, when it was never engineered with performance in mind, is often very, very hard, and it will take a long time. In that time, you're going to be losing money, because you won't be able to offer competitive price on your product, as the server bills will be eating all your margins (and more).
And this is worth noting that this is actually irrelevant to scale. Even with one server if the cost of running that one server is higher than the money you get from your client(s) using that server, you're technically losing money, and it completely does not matter how much you pay your developers. Even if your developers worked for free, you'd still be losing money. The only way out is raising the end price to the customers, but this works only for a short term, until you get competition.
There is also a false dichotomy that you have to significantly pay more for high performance development job. I saw it so many times that a good developer using the right tool created a better performing software in shorter time than another developer using wrong tools, or having skill issues. And you should avoid bad developers for many reasons, not just for performance.
IMHO you should not extrmely optimize everything but you should keep an eye on performance and monitor performance from the early stages of the product. This way even when you cut corners, you do it consciously.
babwawawa@reddit
With systems you are either feeding the beast (adding resources) or slaying the beast (optimizing for performance).
As a PreSales engineer, I’ve found that people prefer to purchase their resources from people who apply substantial effort to the latter. Particularly since there’s always a point where adding resources becomes infeasible.
mr_dfuse2@reddit
that is a useful insight i didn't know, never worked in a company that went beyond step 2. thanks for sharing
BenchEmbarrassed7316@reddit
Although Rust is a much faster language than go, the main difference is in reliability. Rust makes it much easier to write and maintain reliable code. For example, a modern server is multi-threaded and concurrent. go is prone to Data Race errors. Rust, having a similar runtime with the ability to create lightweight threads and switch threads when waiting for I/O, guarantees the absence of such errors.
https://www.uber.com/en-FI/blog/data-race-patterns-in-go/
Uber, having about ~2000 microservices on Golang, found ~2000 errors (!!!) related to data races in half a year of analysis. But if they used Rust, they would have had 0 such errors. And also 0 errors related to null. 0 logical errors related to the fact that the structure was initialized with default values. 0 errors related to the fact that the slice was changed in an unexpected way (https://blogtitle.github.io/go-slices-gotchas/), 0 errors related to the fact that the function returned
nil, nil(i.e. both no error and no result).From a business perspective, it's a question of how much damage they suffered from these errors and how much money they spent fixing these errors. And how much money they constantly spend to prevent these errors from occurring again.
The last question is especially important. Writing code in Rust is faster and easier because I don't have to worry about a lot of things that can lead to errors. For example:
https://go.dev/tour/methods/12
They use the word 'gracefully' but they are lying. The situation is stupid: the
thisargument in a method can be in three states: valid data, data that has been initialized with default values and may not make sense, and null at all. Many types from the standard library simply panic in the case of nil (which is definitely not 'gracefully'). It's a big and unnecessary burden on the developer when instead of one branch of code you have to work with three.We already have horribly designed languages like Js and PHP. Now go has joined them.
Kyrra@reddit
The very first example was already fixed in Go. Specifically the:
This was fixed with the loopvar change in Go 1.22: https://go.dev/blog/loopvar-preview. And I feel like the loopvar bug was one that any compitent Go coder should have known. It's why most people would do something like the following before go1.22:
And many of these can be caught with linters.
BenchEmbarrassed7316@reddit
Yes, this is exactly why Golang is a terrible programming language.
Instead of solving business problems, the programmer spends his effort on knowing a bunch of strange rules. Functions usually return either a result or an error? Well, just remember the standard library functions that violate this rule.
appendcan change data in some cases, and in others during reallocation it does not - well, you have to know how it works from the inside. When working with standard collections like slices and hash maps, in some cases you can use an uninitialized collection and in others - not? Yes, just remember how each specific type works. Also remember that writing to an uninitialized hash map is a panic, and reading is an empty result.lprimak@reddit
Seems like the people are actually buying this. Wow. This is crazy.
rangoric@reddit
Usually it’s premature optimization that is pointless. Measure then optimize and you’ll get results like these.
Fresh_Sock8660@reddit
Yep. Get the code working then profile it for bottlenecks.
KevinCarbonara@reddit
I learned how to profile our software at my first job, and we made some positive changes as a result. I have never done it at any of my other half dozen jobs, ever.
Cultural-Pattern-161@reddit
It is typical. To get to the point where optimization makes sense means that your company is making a lot of money and saturates other areas already aka growing more customers.
For TikTok, saving $300K is kinda small compared to their revenue. It may be worth it but we'll never know because measuring developer's productivity is very difficult. How do you quantify having to manage memory and borrowers? Nobody can't.
ryuzaki49@reddit
Care to provide some insights?
KevinCarbonara@reddit
Just that profiling is good. It's not a terribly difficult thing, we used a professional product, I think JetBrains. It takes some time to learn to sort the signal from the noise, especially if you're running something like a webapp that just has a ton of dependencies you have to deal with, but it's more than worth the effort. Unless efficiency just isn't a concern.
vini_2003@reddit
As a game developer who does graphics programming, profiling is half of my job. Learning to be good at it, spotting patterns and possible points of attention is an extremely valuable skill.
For instance, I took our bloom render pass implementation from 2.2ms to 0.5ms just by optimizing the GL calls and minimizing state changes. I identified the weak points with profiling.
It can be further taken down to sub-0.2ms using better techniques, but our frame budget allows for this.
Same for so many other systems. Profile, people! Profile your code!
preethamrn@reddit
How are frame budgets determined and allocated to teams? How can they tell before the code is written that it will take a certain amount of processing time - what if it's more expensive and turns out they need more budget from another team but that other team can't budge without giving up what they built?
vini_2003@reddit
I work on a small studio so I'm afraid I cannot answer this question from a AAA perspective.
From my perspective, we generally go over performance bottlenecks and desired fixes during weekly meetings. It tends to be mostly me handling the graphical side nowadays (albeit there are others capable of it), so my goal is to keep frame times as low as possible to help everyone out.
Would be awesome to get a dev from a larger studio to share their experience too!
Jaded_Ad9605@reddit
Look at the Friday fun facts fff from factorio.
It explains a lot,,, including performance stuff
vini_2003@reddit
I forgot to reply to your question of "how do we determine frame times?".
Largely, we cannot anticipate them. They vary in-engine based on assets and scenes. It is mostly an experimental process. You can, of course, use past experiences to roughly estimate how long something will take to execute, but most of the time... it depends.
It also depends on the graphics settings involved, quality levels and so on.
I'm afraid the answer is "lucky guess" :)
space_keeper@reddit
I once read something written by an old boy that was very interesting. The context was someone struggling to optimise something even using a profiler.
He said, in a nutshell: run the program in debug and halt it a lot, see where you land most often. That's where you're spending the most time and where the most effort needs to go.
Jaded_Ad9605@reddit
That's profiling by (low) sample rates VS profiling each function call...
Ok-Scheme-913@reddit
That sounds like doing what a profiler does, as a human.. that old boy may feel like going to a factory and doing some trivial task that is massively parallelized and automated by machines by hand.
Like literally that's what the CPU does, just millions of times, instead of the 3 "old boy" did.
space_keeper@reddit
We're talking about quite esoteric C code here. I know what a profiler is and does, I think the guy was suggesting it's just a quick and dirty way to set you on the right course.
FeistyDoughnut4600@reddit
that basically is sample based profiling, just on a very low frequency
Programmdude@reddit
That's essentially what a lot of profilers do.
From what I remember, there are 2 kinds. One traces how long every function call takes, it's more accurate, but it's got a lot of overhead. The other kind (sampling), just takes a bunch of samples every second and checks what the current function is. Chances are, most of the samples will end up in the hot functions.
pmatti@reddit
The term is statistical profiling. There is also event based profiling
uCodeSherpa@reddit
“Just throw hardware at it” is incredibly pervasive and “premature optimization” is just excuse gibberish. The fact is that 99.9999999% of developers throwing this line at you couldn’t tell you whether they are being premature or not. When you ask why something is so slow, they just say “premature optimization. Developer time more than optimization time. Immutable. Functional. Haskell. CRDT” and then they walk away.
And I people like me walk in, spend 30 minutes profiling and get 400x performance benefits taking your ridiculous several hours long report rendering down to milliseconds. The users are so shocked at how fast and responsive shit has become that they think something must be wrong. But no. It’s just that your code was THAT bad because of excuse driven development.
gimpwiz@reddit
Programming has come a long way. Lots of people have lots of experience, and lots of tools and libraries have optimized the hell out of common tasks - tools including the CPUs themselves along with their memories and interconnects and memory controllers, operating systems, compilers, etc.
The way I always put it to our new folks is...
With experience, you simply learn what not to do. You avoid pitfalls before they become issues. You don't need to do crazy optimizations of code when you have no real idea about its performance, but on the flip side, it's not 'premature optimization' to avoid patterns that you know are slow. This applies to everything from SQL queries, to data structures fit well for the task, to knowing not to do n^5 things all over the codebase. It also means that when you do simple and common things, you probably know to write it simply and let the libraries/compilers/CPU/etc optimize it, and stick to simple code for readability, but when you're writing the small pieces of code that are constantly being run inside inner loops and so on, you put a little bit more thought into it. And like other people have said, it also means to profile for hotspots rather than assuming.
MMcKevitt@reddit
A “domain driven detour” if you will
Scared_Astronaut9377@reddit
As someone who's been working for years in ML, big data, high performance computing, I reread your message like 4 times trying to understand the joke.
fiah84@reddit
a lot of us work much less glamorous jobs
greeneagle692@reddit
Yeah most teams never optimize. Your only job usually is pushing new features. I do it myself because I love optimization. If I see something running slow I make a story and work on making it faster myself.
Weary-Hotel-9739@reddit
Rewriting Go to Rust can actually be helpful because of ideology: Rust has a ton more explicit stuff, and many ways to solve a problem, while Go has very few.
While by default you may not speed up that much automatically, rewriting can actually open a lot more doors for further measurements and alternative optimizations for you. Secondly you get a ton of knowledge by a full rewrite. Lastly - most importantly - in a rewrite you loose tons of little edge cases and requirements, and management will often falsely assume those can be redone in a few days later on, while they celebrate the cost savings. For the business, rewrites are nearly always bad until you loose the original developers, but for short term success or even career advice, rewrites are really good for the persons involved.
stdmemswap@reddit
The same can be said to current standard that was not popular back then:
automated tests, version control, code review, static analyzers, containerization
crazyeddie123@reddit
Yeah but Rust isn't just fast, it's also easier to get right than almost any other language out there
rifain@reddit
Premature optimization is not pointless, it's essential. I don't know where this idea comes from but it's used as an argument from lazy programmers to write crappy code.
rangoric@reddit
Might want to look up premature in a dictionary.
Picking what is premature is hard, I do admit.
andrewfenn@reddit
Problem is people will use this phrase to handwave away simply planning and architecture. It's given rise to laziness and I think programmers should stop quoting it tbh except in rare cases it's actually valid.
oberym@reddit
Yes, it’s unfortunately the most stupid phrase ever invented, because it’s misused by so many inexperienced developers and rolls easy off the tongue. The outcome is figuratively speaking people using bubble sort everywhere first because that’s the only algorithm they cared to understand and only profiling when the product becomes unusable instead of using well known patterns from the get go that would just be common sense and as easy to use. Instead they drop this sentence and feel smart when someone with experience already sees an issue at hand.
CramNBL@reddit
This is exactly right. I'm going through it at work right now, multiple times in the same project, I've been brought in to help optimize because the product has become unusable.
I interviewed the 2 core devs at the start of the project, asked them if they had given any thoughts to performance, and if they thought I'd be a concern down the line. They hadn't thought about that, but they were absolutely sure that it would be no problem at all...
G_Morgan@reddit
It is because they don't include the full context of the quote. Knuth was not referring to using good algorithms and data types. He was talking about stuff like rewriting critical code in assembly language or similar.
Full-Spectral@reddit
There's a constant miscommunications on this subject. What is optimization? People don't agree on that. If you tell people not to prematurely optimize a lot of them will go off on you about being lazy and this is why all software is slow and all that. In a lot of cases, it's because they consider 'optimization' to be incredibly obvious things like using the appropriate data structure, which I don't consider to be an optimization. That's just basic design.
To me, optimization is when, after the basic design, which is understandable and no more complex than needed, you measure and decide that (for legitimate reasons not just because) that you need more performance, that you purposefully add complexity beyond the basic design to get more performance. And you definitely don't want to add complexity unless you really need it.
So the arguments just end up being silly, because we aren't even arguing about the same thing. Though I will argue that there is a tendency in the software world to optimize (in my sense of the word) when it's not necessary, just because people want to be clever, or they are bored, or whatever it is.
Nine99@reddit
Calling it "premature" is already making a judgment, so the actually meaningful part of the quote is the amount of evil, i.e. the second part of the quote.
oberym@reddit
And in this case it is totally valid. Unfortunately in practice, I've never heard it in this context but in discussions about the most basic things. And that's where the danger with oversimplified quotes lies. It's now used to push through the most inefficient code just because "it works for now" and avoid learning better general approaches to software design that save you more time right from the start. And hey it came from an authority figure and everyone is quoting it all the time, so it must always be true. It's more like using quotes out of context is the root of all evil.
SkoomaDentist@reddit
He wasn't doing even that. He was referring to manually performing micro-optimizations on non-critical code.
Ie. changing func(a*42, a*42); to b = a*42; func(b, b);
NYPuppy@reddit
I think every common phrase is like this, programming or not. The quote wasnt against optimizing and was NOT against "optimizing" early. Performance and good design is something that programmers should always consider.
taintedcake@reddit
They also had an intern do it, not a senior developer. They didnt care if there were results, it was just a task given to an intern for them to fuck about with
moratnz@reddit
Yep; premature optimisation may be the root of all evil, but if the optimisation will return a $300k savings in return for a few thousand dollars worth of engineer time, then it isn't especially premature (well, unless there are any fruit hanging even lower).
nnomae@reddit
Tik Toks daily revenue is close to $100 million a day. Even if we charitably assume that doing that basic optimisation as they went would have only delayed their launch by a single day it would have cost them a full days revenue or $100 million.
catcint0s@reddit
Launch what? They optimized an existing service that was written in Go (so it was launched faster).
coderemover@reddit
> so it was launched faster
Quite debatable. I haven't seen much evidence Go makes people launch things faster. For sure it makes them compile faster, but Go is not the language where you can say "if it compiles, it works".
catcint0s@reddit
I don't think this is debatable, it's from the employee who did the Rust rewrite and actually works there...
The linkedin post also mentions it but I think it's based on the blog post too
Full-Spectral@reddit
The thing is though building and iterating are not the ultimate goals of software development. That's a developer convenience, but the software is being developer to be used by other people, and it's their convenience (not up on saturday night trying to fix an issue) and their security and so forth.
coderemover@reddit
This is just how Go is perceived and this is at least partly because it was advertised like that. We have some Go teams in our company and from the outside I can’t see they are any more productive than developers using other languages.
So why people may think they are more productive, there is very little evidence they really are. Google actually measured that and found no significant differences between Go and Rust productivity.
All_Up_Ons@reddit
No one's saying you should delay your launch. They're saying that once you have launched and are making money, you can afford to look for these optimizations.
Qweesdy@reddit
They could've started working on it one day earlier, spent 1 day in rust instead of spending 1 day in some other language, had the launch date one day earlier, got to "$100 million per day" twice as fast because it's less laggy, and be getting $200 million per day now.
You're just bad at fabricating idiotic and irrelevant hypothetical fantasies (like seriously, why were there no unicorns in your absurd hallucination?).
tu_tu_tu@reddit
You can replace "premature optimisation" with "optimisation don't supported by at least minor research". That would makes sense.
coderemover@reddit
Counterpoint: after getting enough experience you don't need to measure to know there are certain patterns that will degrade performance. And actually you can get very far with performance just applying common sense and avoiding bad practice. You won't get to the 100% optimum that way, but usually the game is to get decent performance and avoid being 100x slower than needed. And often applying good practices cost very little. It doesn't need a genius that if your website does 500+ separate network calls when loading, it's going to be slow.
rangoric@reddit
Then that's not premature. For a lot of things that you've learned, there's a reason you do them. You've already measured it.
The main idea is to not optimize something that isn't a problem. This service that was optimized for instance. It was good enough. It worked on task and did what they wanted.
But they had measurements around it and knew if they could get it to go faster, they could get some gains either in throughput or decreased costs. So, when it was redone, they could point out that it was better with numbers instead of guessing. Next time they might start with Rust for short-lived or very fast microservices. But what they did to start this one was perfectly fine and did what it needed. If they spent a ton of time writing both versions to see what was better at the start of the project, it would have delayed things (twice as much work) and would it have shown the same gains unless under load? So many things it's hard to know up front.
So, I guess my counterpoint is that it's hard to know when it's premature. If you don't have a solid reason and are guessing, that's where I usually draw the line.
Caching for instance is a perfectly normal thing to do. But on the web, it's way more important to do it up front for large files than small files that can change. So, if you are making your own image server, caching isn't premature. Reducing file size isn't premature. Doing things to reduce the number of calls to a reasonable number isn't always premature but depending on the tomfoolery you do here, some things you do might be.
Because if in reducing the number of calls you can't cache as much, you will need to measure that, or break it down in ways that make it obvious that without measurement it will be fine (sprite sheet for commonly used icons/images). So yes, a lot of it really depends.
But saying optimization is pointless? I never see developers say that. If I said that I'd get blank stares of disbelief. Along with "Who are you and what do you do with him?"
G_Morgan@reddit
Premature micro optimisation is more than pointless, it obscures the intent of the code and makes it harder to do the right thing.
MachinePlanetZero@reddit
Ie "please deliver not completely awful working software that does what was asked", and if you manage to hit that milestone, then just maybe you can then also think "is any of it slow"
nerdly90@reddit
📠
BibianaAudris@reddit
Considering China's tax rates, it is actually a net loss if they paid for Rust code maintenance $150k+ per year. Optimization starts making sense when they could hand over everything to a single intern.
1RedOne@reddit
I did something like this to save on ru consumption and the graphs I made tracking the before and after…mamma Mia
They could have fired me and I would have shown up anyway just for the satisfaction of seeing that line of ru consumption plummeting
poopatroopa3@reddit
Gotta profile you stuff
lprimak@reddit
This reeks of total BS. Period. Full stop.
CedarSageAndSilicone@reddit
Literally no one claims optimization is pointless at scale. Optimization is pointless if your infrastructure costs will stay the same regardless.
Kyrra@reddit
I don't see the word
pprofanywhere in this post or in this reddit thread. Doing a quick pprof look at the service likely could have found any slowness in the Go version of this app without a lot of work. This honestly sounds like someone just wanted to rewrite in Rust, rather than trying to dive into the "why" part.eSarwin@reddit
I feel at home with Golang, but things like this sometimes make me wonder if I should try Rust or stay focused on building.
ZakanrnEggeater@reddit
didn't Twitter do something similar switching from a Ruby interpreter to a JVM implementation for one of their message queues?
lxe@reddit
300k per year sounds impressive but their infrastructure costs are 800 million. It’s not that impressive — it’s like you saving $100 every year.
NovelPuzzleheaded311@reddit
That's less than my Adderall budget.
metaldark@reddit
At my job our service teams can’t even get cpu requests correct. At our scale we’re wasting dozens of vcpus.
NovelPuzzleheaded311@reddit
Meanwhile our devops guys insisted on all ephemeral storage being limited to 5MB because they are too ignorant to realize stdout counts towards that.
Guess what? Our pods fucking die every 10-15 minutes now, and they are scratching their heads wondering why.
Ok_Builder910@reddit
This is nothing for TikTok.
Data_Scientist_1@reddit
Something's shady about the article. It doesn't explicitly say how was the golang service implemented and where did they hit their bottleneck. Also, don't sketch why they were having those issues in the first place.
coderemover@reddit
It's interesting to read it was an *intern* who did it. Not a super senior low level optimization wizard who learned PDP-11 assembly in kindergarten and C in primary school. So yeah, to all those people who claim Rust is hard to learn - Rust is one of the very few languages I'd have no issue throwing a bunch of interns on. As long as you forbid `unsafe` (can be listed automatically) they are going to make much less trouble than with popular languages like Java or Python.
Weary-Hotel-9739@reddit
Oh yes, that wall of difficulty for async or macros doesn't exist.
coderemover@reddit
For you it’s a wall, for me it’s just another tool in the toolbox. And I disgress - async and concurrency in any language, be it Java or Go or C# is just as hard as in Rust, but even more error prone.
Leading_Detective292@reddit
The core essence here that's essential to grasp is the scale, as a company grows and develops and slowly becomes a giant, naturally many flaws will appear or 'inefficiencies' that , once solved, can save a ton of money.
That's also partially why companies are trying their best to get into AI.
Hope that helps.
MaterialRestaurant18@reddit
Oh brother....reddit...how can you believe such a bull fucking shit story when the source is LinkedIn and no name has been dropped.
InfinitesimaInfinity@reddit (OP)
There are three reasons why I believe it.
First of all, $300000 is relatively small in proportion to TikTok's revenue. Second of all, the intern wrote an article about it, which is at https://wxiaoyun.com/blog/rust-rewrite-case-study/ . Third of all, I saw a few other sources claiming it online, including another LinkedIn post, a Youtube video, a Reddit post, etc.
ChadiusTheMighty@reddit
Did he get a return offer??
InfinitesimaInfinity@reddit (OP)
I do not know.
BarfingOnMyFace@reddit
Uh… 300K is chump change… are you missing a zero perhaps?
Rodditor_not_found@reddit
Lemme guess...all he got in return was a pat on the back and a slice of piza
Radstrom@reddit
I'd say the bigger the scale, the more significant the savings can be. We aren't rewriting shit in rust to save a couple of dollars. They can.
ldrx90@reddit
300k annual savings is really good for most startups I would imagine. That's what, a few engineers worth of salary?
LukaManuka@reddit
Yes, but TikTok has more than 1.5 billion users. Billion. That's almost 20% of the population of the entire world. And even at that colossal scale, this optimization is still only saving them $300k, which amounts to just $0.0002 per user.
If a startup had even 1.5 million users (which is still vastly more than the overwhelming majority of startups), they'd save a meager $300 per year. That's maybe a single day's salary for an engineer (if even that).
a_better_corn_dog@reddit
If you consider stock, bonus, benefits, and taxes; 300k is more realistically one senior engineer or maybe two SE1/2s.
scodagama1@reddit
Eeee but Tik Tok is not a startup
If your startup is - let's assume optimistically - just 100 times smaller than Tok- Tok and saves $3000 in that optimization that doesn't sound like worth of rewrite by intern anymore, does it?
If you're in hyper scale then of course optimisation matters, who has ever claimed otherwise?
-grok@reddit
yes thank you, watching people not understand this has been driving me nuts.
And even worse, that intern "rewrite" is likely riddled with bugs that will show up to customers as "why would I use this garbage product?" and hurt the startup's traction anyway. The value is easily in the negative $1M and not positive $300 bucks.
scodagama1@reddit
Nah it's not that bad probably - keep in mind this is intern bragging about rewrite
He had mentors, probably senior engineers who reviewed his code and guided him through implementation, rust experts on site and most importantly extensive suite of integration tests and state of the art production monitoring so he could confidently write couple of lines of code, deploy it to staging environment, let it bake for 2 weeks and merge
That's another thing that startups don't realize: these big corporations have top notch engineering practices and state of the art CI/CD and monitoring infrastructure. You don't operate 1.5b users business without entire business divisions focused solely on reliability.
It's easier to do rewrites when you have all this infrastructure in place, it is specifically designed for evolvability of software
F4underscore@reddit
Thanks for putting it into perspective. Kinda crazy how tiktok has 1.5B users right now
scodagama1@reddit
Yeah these hyper-scalers are insane. Unfortunately a lot of smaller companies tends to copy what hyper-scalers do because clearly if Amazon/Google/Meta does something it must be good, doesn't it?
Sure it is - at that scale. What they forgot to look at is how Amazon operated when they were a startup - bezos hacking together some c++ shit that took 2 hours to compile in his garage which powered the e commerce operation for 10 insane growth years before they saw a need to do micro services. Startups should operate like Bezos in 1997, not like Bezos in 2022 - correcting for technological progress obviously
TheSkiGeek@reddit
Yes, but they probably saved $300k from $1M+ that they were spending every year. Most startups aren’t going to be handling that level of traffic or need anywhere near that much cloud compute.
Iamonreddit@reddit
You may want to reframe your point if you want it to be more impactful.
TheSkiGeek@reddit
30% of small number is small.
30% of big number is big.
Engineers expensive.
nemec@reddit
One of the products I work on spends a little more than $300k/y on just one microservice for probably less than 10k monthly users. We could save so much money rewriting it with containers but it's "only" one or two developers worth so no... we just bumped our lambda provisioned concurrency to 200 and let it chug along lol
mattgen88@reddit
I'd be rewriting as a hobby... Are you just busy-waiting to heat a data center!?
getfukdup@reddit
yea, their salary, but the cost of an employee is several times their salary.
jl2352@reddit
It is, if you can find such a saving in your startup. Most startups won’t be able to find that.
Days_End@reddit
No, it's not even a single engineer. Remember the general rule of thumb is it costs the company 2x your salary to employ you.
Coffee_Crisis@reddit
If an optimization like this saves you this kind of money you are not a startup anymoee
safetytrick@reddit
And in my startup with a hosting cost of 2mil a year one service improving by 90 percent is a 1000 dollar savings. I'll bring you donuts if you don't bill more than $20 an hour.
ldrx90@reddit
Well sure, do the estimates before comiting to the work. I was mostly just thinking this amount of work for 300k isn't necessarily 'a couple dollars'. This amount of work probably doesn't go as far as 300k in savings though for most smaller places, for sure.
All I'm saying, is if I could rewrite a few endpoints in a new language and save 300k a year, I'd get a fat bonus.
safetytrick@reddit
Engineering is about cost/benefit. If it costs more than it benefits...
zzrryll@reddit
It wasn’t a startup. It was TikTok. So this change wouldn’t apply at the scale of any startup that would care about that savings.
Especially because we haven’t seen this play out. Are they going to have to rebuild this in a year, with a team of engineers? Headlines like this are always kinda trash imo….
Upstairs-Party2870@reddit
They probably hired that intern for <30k
beyphy@reddit
If they can repeat this across multiple microservices, those savings can really add up. Assuming they save a similar amount, they only need to do this to three more microservices before their savings are greater than $1M. And obviously the more microservices they're able to do this for, the greater their savings will be.
snurfer@reddit
More like a single engineer when you take total package (salary, equity, benefits, bonuses).
metaltyphoon@reddit
In the US
autoencoder@reddit
right. More like 10 in Romania
Matt3k@reddit
Uh huh. Not everyone is a silicon valley startup funded with magical unicorn money or FAANG. $300k/yr engineer. Yeah okay. That is literally the 99th percentile of engineer salaries.
a_better_corn_dog@reddit
I'm at a company similar to the size of tiktok. A teammate saved us 150k per month on compute costs with a few minor changes and it was such a drop in the bucket savings, management was completely indifferent to it.
300k/yr sounds like an insane amount, but for companies like TikTok, that's peanuts.
kane49@reddit
Who the hell claims optimization is useless because computers are fast, that's absolute nonsense.
Pearmoat@reddit
"Many developers" of course, who some random dude on the internet invented so he'd have an argument that he can disprove in a post.
PatagonianCowboy@reddit
Usual webdevs say this a lot
"it doesn't matter if it's 200ms or 20ms, the user doesnt notice"
v66moroz@reddit
Nope, webdevs usually say "since my bottleneck is DB, it doesn't matter if my service is written in Ruby or Rust". Besides "normal" web app is easy to scale by adding boxes (hardware is cheap, isn't it?). May not apply to TikTok, but true for most business apps.
PatagonianCowboy@reddit
Well there is a webdev in the other comments literally insisting 200 and 20ms are the same because the user doesn't notice
v66moroz@reddit
It's not a usual webdev, web app doesn't usually have exactly one user. He's right about latency though.
TA_DR@reddit
Which is totally true when talking in the webdev context.
PatagonianCowboy@reddit
Source?
For example:: Speed Matters
TA_DR@reddit
https://web.dev/articles/inp
"An INP below or at 200 milliseconds means a page has good responsiveness."
PatagonianCowboy@reddit
no data, not an actual source
gheffern@reddit
Definitely not.
TA_DR@reddit
https://web.dev/articles/inp
"An INP below or at 200 milliseconds means a page has good responsiveness."
For that case is totally true. Once you reach <200ms there is no need to further optimize since users won't be able to tell the difference.
And of course that isn't neccessarily true for other cases.
Nine99@reddit
You're quoting a subjective (and moronic) statement on a broken, incredibly slow website as a fact, and then follow that up with stuff you pulled out of your ass.
TA_DR@reddit
well every design choice is subjective. In this case it's google's design choice so I'm sure they have the data to back it up.
Nine99@reddit
Didn't know that Google devs can read minds now.
Hey, but I'm sure they've linked some research about it in the article. They don't? What a surprise!
TA_DR@reddit
Well, MDN recommends 100ms. Which is in the same order of magnitude. The point is still the same, there is no reason to optimize user interactions under that time.
Nine99@reddit
"Poor responsiveness" is also in the same order of magnitude according to your source.
usernamedottxt@reddit
At massive scales this is pretty much proven false. Amazon and Google both have published research on it.
PatagonianCowboy@reddit
Yeah, there is a reason why Cloudflare uses Rust to process 90 million requests per second: https://corrode.dev/podcast/s05e03-cloudflare/
Speed matters
TA_DR@reddit
that's amount of request, not loading time perceived by the user.
PatagonianCowboy@reddit
I know, that's what I wrote
TA_DR@reddit
well yeah, but I'm talking about user interactions. Not response handled per second.
200ms is enough for INPs. For that case there is no need to further optimize.
PatagonianCowboy@reddit
yeah sorry is just that you edited your comment like 4 times
Nine99@reddit
Maybe Cloudflare should stop adding several seconds (sometimes dozens) of loading time to gazillion of websites.
TA_DR@reddit
web.dev (google's guidelines) clearly state that under 200ms is the bar for NPI
BlueGoliath@reddit
No one should listen to webdevs on anything performance related.
HarryBolsac@reddit
Theres plenty to optimize on the web wdym?
BlueGoliath@reddit
Incredible.
All_Work_All_Play@reddit
I think they mean that bottom tier web coders and shitty html5 webapp coders are worse than vibecoders.
jjeroennl@reddit
It kinda depends how fast things improve. This was definitely an argument in the 80s and 90s.
You could spend 5 million in development time to optimize your program but back then the computers would basically double in speed every few years. So you could also spend nothing and just wait for a while for hardware to catch up.
VictoryMotel@reddit
It was even more important back then. Everything was slow unless you made sure it was fast.
Also where does this idea come from that optimization in general is so hard that it takes millions of dollars? Most of the time now it is a matter of not allocating memory in your hot loops and not doing pointer chasing.
The john carmack doom and quake assembly core loops were always niche and are long gone as any sort of necessity.
Coffee_Crisis@reddit
The point is that as long as you ship code that scales linearly or better there are generally very few opportunities to actually save money through performance optimization
VictoryMotel@reddit
Says who? Everything scaled linearly back then because click speeds were jumping up and instruction times were going down.
This idea that optimization was difficult or ineffective is just not true at all.
Where are you getting this idea and what is a real technical example?
Coffee_Crisis@reddit
I’m talking about now, and the OP is a good example - 300k is money TikTok finds in the couch cushions. If you don’t have that scale the optimization isn’t worth doing, “hard” is irrelevant. Its not about hard or easy, it’s about opportunity cost
VictoryMotel@reddit
The thread wasn't about that
So what?
This was a rewrite so not typical optimization, but optimization is not difficult and it is worth doing any time something shows up as slow on profiling of a system or individual program.
It isn't just huge scale and throughput, slow software can lead to bad latency and the inability to handle traffic spikes. Interactivity suffers.
Coffee_Crisis@reddit
You’re jus arguing against considering ROI when taking on performance tasks and it’s dumb and I’m not engaging any more, take care
omgFWTbear@reddit
… one of them became a chip instruction …
VictoryMotel@reddit
You misunderstand the context and point of conversations quite a bit I'm guessing.
omgFWTbear@reddit
A footnote to a footnote to a footnote is rarely understood as being substantive to the main thrust of a text, hence the acceptance of removing it so far from the flow.
For example, one should be reasonably well aware that an overwhelming majority of development is not done at the instruction level.
VictoryMotel@reddit
Sober up, this isn't even close to being coherent.
omgFWTbear@reddit
Pretty telling that if something doesn’t make sense to you, you infer inebriation.
Some folks enjoy topics and errata for conversation’s sake, not grounding everything into a correct answer to a technical problem.
VictoryMotel@reddit
What are you even talking about, nothing you're saying makes sense.
You seem like someone who is so in their own head they can't connect what they say to a conversation but they blame everyone else for not understanding.
jjeroennl@reddit
When dealing with teams 5 million of spent in no time.
VictoryMotel@reddit
What are you even talking about? With zero context you just pulled a number out on thin air.
Optimizing isn't that hard. You profile and life things out of hot loops, mostly memory allocation. In modern times you avoid pointer chasing and skipping around with memory access.
Have you ever done this before?
In the 80s and 90s it was all about speed. If you just waited for computers to speed up someone else was going to move in on your territory. A fast program was still going to be faster on a new computer.
DevilsPajamas@reddit
Your comment reminded me of the tv show Halt and Catch Fire... one of my all time favorite shows.
versaceblues@reddit
its more that people care less about optimization in the early stages. Which is good.
If you are launching to <10,000 customers then time to market is better than optimizing for CPU cycles.
IF you are serving at global scale. Then optimization can actually translate to cost
TimMensch@reddit
Yes and no.
If you launch to a smaller number or customers but then get a usage spike that kills your servers, you'll be hemorrhaging customers until you can rewrite it to be a decent architecture.
A good developer can optimize to the point of reasonable scaling in less time than a mediocre developer can create a really purely optimized backend. I've seen several backends that were so badly optimized that scaling to just a dozen users caused each user to need to wait ten seconds to do anything. Whereas the same server rewritten by a skilled backend developer could hit a million users with low latency.
I've also seen projects completely killed when they realized the backend would cost more to run per user than the users were willing to pay.
The problem is that it takes a strong developer/architect to do it right the first time, and we're expensive. Not as expensive as losing customers and needing to rewrite later while losing customers though.
versaceblues@reddit
There is definitely a balance to strike. I like to apply Yagni https://martinfowler.com/bliki/Yagni.html
TimMensch@reddit
Does YAGNI even apply when the strong developer can do the work in less time and with less complexity?
Seems orthogonal.
Regardless, you're only not going to need it if the company fails before anyone uses the app. Not exactly a good thing to hope you won't need. 😜
versaceblues@reddit
YAGNI is not about being lazy, its a prioritization framework.
If you can make the software more robust and future proof with minimal effort its encouraged.
If you are going to spend 3 weeks optimizing for a 2% CPU use efficiency that is going to be immaterial to current customers, then you are incurring opportunity cost on actual features that you could be building.
TimMensch@reddit
Sure? I'm saying that a good developer really doesn't need to spend longer to get to a point of reasonable performance.
The failure is usually in not hiring a good developer. Spending three weeks for a tiny optimization is a rookie mistake.
beefz0r@reddit
Optimization is only useless when it never hits 100%
alkaliphiles@reddit
It's really about weighing tradeoffs, like everything. Spending time reducing CPU usage by 25% or whatever is worthwhile if you're serving millions of requests a second. For one service at work that handles a couple dozen requests a day, who cares?
uCodeSherpa@reddit
Your users suffering 50 second web page loads care a lot.
/r/programming has this huge skill issue with thinking about their application from the user perspective. I swear none of you people ever actually use the dogshit you pedal.
NYPuppy@reddit
Because it adds up.
Developers take that attitude with apps they write and now everything ships a web browser and runs slow.
dangerbird2@reddit
Also there’s an inherent cost analysis between saving money on compute by optimizing vs saving money on labor by having your devs do other stuff
alkaliphiles@reddit
Prefect is the enemy of good
And yeah I know I spelled that wrong
dangerbird2@reddit
I would say a lot of software is far from perfect and could definitely use optimization, but ultimately ram and cpu costs a hell of a lot less than developer salaries
St0n3aH0LiC@reddit
Definitely, but when you use that reasoning for every decision without measuring spend, you star spending 10s of millions on AWS / providers per month lol.
Been on that side and the sides where you are questioned for every little over provisioning, which also sucks haha
As long as it’s measured and you make explicit decisions around tradeoffs you’re good.
tcmart14@reddit
This gets into an interesting bit, potentially, and what I am dealing with at work.
We know these are trade offs and try to make a choice based on them, how often though, are organizations re-evaluating?
At my current job, there is a tendency to stand up stuff and we initially make a choice. And at that time, it works with the trade offs. But then the organization has no practice or policy about monitoring and re-evaluating. The trade offs you made 3 years ago were fine for years 1 and 2, but now here at year 3, things have drastically changed. I imagine this is common, at least at smaller shops like mine.
St0n3aH0LiC@reddit
Great points. I feel like these things don’t get revisited until companies are at a scale where there are dedicated teams and tooling around assessing costs.
When you get pinged that something hasn’t hit > 1 % utilization in the last 3 months and downsizing it would save $X a year to your org, then this sort of stuff gets revisited and it’s also easier to manage on an ongoing basis.
Definitely tricky at a smaller shop where this stuff isn’t being poured thru regularly.
Rigberto@reddit
Also depends if you're doing on-prem or cloud. If you've purchased the machine, using 50 vs 75 percent of its CPU doesn't really matter unless you're opening up a core for some other task.
particlemanwavegirl@reddit
I don't really think that's true either. You still pay for CPU cycles on the electric bill whether they're productive or not. Failure to optimize doesn't save cost in the long run, it just defers it.
hak8or@reddit
That cost is baked into the cloud compute costs though? If you get a computer instance off hetzner or AWS or GCE, you pay the same if it's idle or running full tilt.
On premises then I do agree, but I question how much it is. Beefy rack mount servers don't really care about idle power usage, so it doing nothing relative to like 50% load uses very similar amounts of power, it's instead that last 50% to 100% where it really starts to ramp up in electricity usage.
coderemover@reddit
If it's mostly idling, you can rent a smaller instance, or fewer instances and pay less.
particlemanwavegirl@reddit
In that sort of case, I suppose the cost is decoupled from the actual efficiency, in a way not entirely favorable to the consumer. But saving CPU cycles doesn't have to just be about money, either: there's an environmental cost to computing, as well. I'm not saying it has to be preserved like precious clean water but it I don't think it should be spent negligently, either. There's also the case, in consumer-facing client-side software, that a company may defer cost of development directly onto their customer's energy footprints, and I really think that's an awful practice, as well.
Coffee_Crisis@reddit
If your engineers aren’t delivering more value than the electric utility bill you have bigger problems than slow code
particlemanwavegirl@reddit
I think your footprint matters no matter how it compares to revenue. Taken to it's logical conclusion if everyone acts like that we get late-stage capitalism, choking to death on our own fumes.
Coffee_Crisis@reddit
If you are getting hung up on this you need to start quantifying actual emissions and realize you are talking about maybe tanking your startup in order to prevent emissions equivalent to 10 minutes of a passenger jet flight
swvyvojar@reddit
Deferring beyond the software lifetime saves the cost.
particlemanwavegirl@reddit
Yeah, I can't argue with that. I think the core of my point is that you have to look at how often the code is run, where the code is run doesn't really factor into like that.
kane49@reddit
Of course but "my use case does not warrant optimization" and "optimization is useless" are very different :p
TheoreticalDumbass@reddit
yes, but most people think of statements within their situations, and in their situations both statements are same
omgFWTbear@reddit
I’ve found the savage behind the GTA:O startup JSON dedupe code!
macnamaralcazar@reddit
Not just who cares, also it will cost more in engineering time than what it saves.
midorishiranui@reddit
every microsoft dev apparently
FamilyHeirloomTomato@reddit
99% of developers don't work on systems at this scale.
pohart@reddit
Mostb apps I've worked on have benefited from profiling and optimization. When I'm worried about millions of records and thousands of users I often start with more efficient algorithms, but when I've got tens of users and hundreds of records I don't worry about choosing efficient algorithms. Either way I went up with processes that are slow that need to be profiled and optimized.
Full-Spectral@reddit
And, shocking though it seems, some of use still even write software that's not cloud based and that has nothing to do with databases. So many people work in cloud world these days that they assume their concerns must be universal.
Coffee_Crisis@reddit
I am responsible for systems with millions of users and there are almost never meaningful opportunities to save money on compute. The only place there are noticeable savings is in data modelling and efficient db configs to reduce storage fees, but even this is something that isn’t worth doing unless we are out of product work
pohart@reddit
I'm talking user noticable delays.
Coffee_Crisis@reddit
User perceptible performance issues counts as product work imo
pohart@reddit
Sure, but they still get profiled and optimized if there's an issue.
I've got all dedicated servers on-prem unless there's a catastrophe, so I'm not terribly concerned with compute.
Sisaroth@reddit
Most apps I worked on where IO (database) bound. The only optimization they need was the right indexes, and rookies not making stupid mistakes by doing a bunch of pointless db calls.
NYPuppy@reddit
But they do work on SOMETHING. I think a lot of people see this as a binary between optimizing and not. It's not. Performance is always important, it's just that what is considered performant differs.
hitchen1@reddit
It's still important in web regardless of scale though, since page load is linked to conversion rate.
Waterty@reddit
Say you're an out of touch snowflake without saying it
zettabyte@reddit
One needs a straw man to tear down when making a dubious claim.
not_logan@reddit
Managers do
Trapick@reddit
It's more that if you have a webapp with 12 customers, don't worry about spending the time to optimize that call from 10ms to 2ms. If you have 2 billion customers then yah, that's a different problem.
ilep@reddit
It used to be so, back when there was huge uptick in Java usage and Moore's law wasn't completely dead yet. When clock speeds stopped increasing regularly people started to pay attention to software.
buttplugs4life4me@reddit
"The biggest latency is database/file access so it doesn't matter" is the usual response whenever performance is discussed and will instantly make me hate the person who said that.
KFUP@reddit
Real optimizations are not useless, but it's different for nano optimization like this one -that made the news for whatever reason- that would take 1000 years to save tiktok 1% of 1 year revenue.
That's a poor use of the engineers time, they could spent that time working on something with real impact like new features or fixing bugs.
spooker11@reddit
The argument often makes sense when bootstrapping a small company. Engineer time is more expensive than compute time so it’s better to move faster as an engineer than slower and build more performant software
That shifts once you begin exceeding certain level in scale. When you start hitting that scale you already have the time and money to go back and begin optimizing the slower costlier things for performance
___Archmage___@reddit
There's some truth in the sense that it's often better to have really simple and understandable code than doesn't have optimizations rather than more complex optimized code that may lead to confusion and bugs
Personally in my career in big tech I've never really done optimization, and that's not a matter of accepting bad performance, it's just a matter of writing straightforward code that never had major performance demands to begin with
In any compute-heavy application though, it'll obviously be way more important
Omni__Owl@reddit
I have heard this take unironically. "You don't have to be as good anymore, becuase the hardware picks up the slack."
ummaycoc@reddit
Bad management…
teddyone@reddit
People who make crud apps for like 20 people
PatagonianCowboy@reddit
Those people have the strongest opinions about programming
amnesiasoft@reddit
Yes... But also a CRUD app with 20 users at work is actually one of the only apps I've spent significant time optimizing because it processes absolutely way too much data per user.
coldblade2000@reddit
Depends. Did it take 1 month of an intern's time to reduce lag by 200ms, or did it take a month of 30 experienced engineers time?
BlueGoliath@reddit
"high IQ" people on Reddit?
trialbaloon@reddit
Python developers I imagine.
poopatroopa3@reddit
I'm a Python dev who optimizes stuff. We exist
trialbaloon@reddit
Ha I believe it. To be honest I am mostly joking, mostly....
StochasticCalc@reddit
Never useless, though often it's reasonable to say the optimization isn't worth the cost.
HRApprovedUsername@reddit
Depends on what you’re optimizing
palparepa@reddit
Management.
Bradnon@reddit
People who "get it working on their dev machine" and then ship it to prod with no respect for the different scales involved.
PhatOofxD@reddit
The number of companies running at that scale can be counted with not much difficulty. 99% of developers will never work on something that large and for 99.99% of businesses it's useless.
scalablecory@reddit
Just about any time you see "way faster after switching to language X" when it comes to one of the systems-level languages, keep in mind that the platform is rarely the main contributor. Most of the gains are likely due to the original code simply leaving performance on the table and needing a rewrite.
BenchEmbarrassed7316@reddit
https://www.reddit.com/r/programming/comments/1okf0md/comment/nmbwkyn/
In this post I described the technical issues of go that significantly affect performance. A simple language change solves them all and provides "free" performance.
pm_plz_im_lonely@reddit
To what language and what library?
Cause if it's Rust you get Macro expansions or C++ with nlohmann's it's also also a macro. Both cases guess what if you want fast object mapping it's code generation.
BenchEmbarrassed7316@reddit
Yes, I'm comparing it to serde. I don't quite agree: Rust uses macros in this case for compile-time reflection (you just need to know the field names and types). But that's not the only problem with go.
https://www.reddit.com/r/programming/comments/1okf0md/comment/nmg4uzm/
Check these examples. go uses a separate heap allocation for each optional field.
https://www.reddit.com/r/programming/comments/1okf0md/comment/nmc8hvg/
This comment and the replies to it discussed other options. In short, it's a choice between bad and bad.
It's surprising that a language focused on web services works so poorly with JSON.
ps And I feel awkward turning my answer into a bunch of links..)
i-can-sleep-for-days@reddit
At my company we only allow 3 or 4 languages to keep the cognitive context switching down. Nothing worse than that intern’s project going down at 3 am and it is written in a language you don’t know and the intern is long gone.
keithstellyes@reddit
Premature optimization is the issue. It's just that the answer to win isn't a problem you're solving with just a quip or two.
Ideally, research, thought, and data is there
Background_Success40@reddit
I am curious, do we know more details. Was the high CPU usage due to Garbage Collection? The author of the blogpost mentioned a flame graph but didn't show it. As a lesson, what would be the trigger to move to Rust? Would love some more details if anyone has it.
BenchEmbarrassed7316@reddit
https://www.reddit.com/r/programming/comments/1okf0md/comment/nmbwkyn/
go has a poor design. If you need to deserialize a data structure that has 10 optional fields which are for example
geoPoint { x: int, y: int }structures - you will get 10 extra allocations. And work for GC.Background_Success40@reddit
Not sure I understand, couldn't we set these as pointers and allocate them when needed?
BenchEmbarrassed7316@reddit
Here is go code:
https://go.dev/play/p/-RT_7qcUYwP
go run -gcflags="-m" test.goAs you can see, without pointers, go cannot distinguish between null values and zero values. And in the case of pointers, we will get heap allocations (although it also puts the local variable on the heap, which is generally funny).
And here is Rust:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=bee463333d2a161d1bbe0841c57559f4
It's definitely stack.
Background_Success40@reddit
Thanks for the examples! Much appreciated.
richizy@reddit
I dunno if that is "poor" design. It's consciously trading raw performance for ergonomics, as the dev doesn't have to worry about writing deserialization code (ie just use proto.Unmarshal).
There are ways to deal with allocation. You can manually check and extract the optional fields (lazy loading). Or you can make the proto completely flat so no extra allocations.
There's also custom proto code generators like vtprotobuf (by Vitess/Planetscale) which does allocations optimally.
egonelbre@reddit
You can serialize these into a
type GeoPoint struct { Valid bool; X, Y int32 }or other similar approaches. Wrap it in type safety, if you want. Alternatively, bulk allocate during deserialization.BenchEmbarrassed7316@reddit
Sorry, but this is nonsense. Now all code that works with
GeoPointhas to check this flag. Maybe it should add unhappy path handling. This is just making the code more complicated where everything should be simple. These checks will also hurt performance instead of a single check during deserialization. And it doesn't work with scalar types.This is the case where "simple" go makes writing code complex, and conversely "complex" Rust makes writing code simple.
egonelbre@reddit
If it's an optional field, then the code needs to check something anyways. Even Rust needs to check whether the field is present.
Why wouldn't it work for scalar types?
BenchEmbarrassed7316@reddit
The check should be located where it is checked whether this field exists or not.
If you add an extra field - 'process' will actually receive an additional argument 'isVaild'... What to do with it? Check? Ignore? If I work with 'process' function in a few months - I have to somehow guess that 'isValid' was added solely because of the broken deserialization and not because it is some kind of coordinate check that makes sense from a business logic point of view. And if I create 'GeoPoint' separately in code - should I always add 'isValid: true'?
Because you can't add additional field 'isValid' to int.
egonelbre@reddit
As I mentioned there are multiple variations on that approach. I suspect you are looking for this in that scenario:
You can see similar types in quite a few places, e.g. https://pkg.go.dev/database/sql#Null. Don't get me wrong, it's annoying that each package ends up implementing their own types.
See above.
BenchEmbarrassed7316@reddit
Now you just have to make sure that the
deserializefunction (which is most likely imported from another package or standard library) can correctly work with thisOptionaldata type and will not try to look for theValidandValuefields in the serialized data.ps I also think that generics should have been there from the very beginning of go.
egonelbre@reddit
Sure, I agree to both. Maybe less strongly about generics, but it definitely would've avoided plenty of API issues.
egonelbre@reddit
PS: don't get me wrong, I think builtin optional type is a great feature that would simplify interop between libraries.
BenchEmbarrassed7316@reddit
I think it is the necessary minimum for comfortable, fast, and reliable development.
Impossible_Way7017@reddit
Is go good for web apps? I thought it was mainly for cross platform executables.
germandiago@reddit
This is the reason why I still do C++ in swrver-side for heavy services or I would recommend people something like Rust as well.
They are very fast and second to none in this area.
atehrani@reddit
I bet it was not well written in Go to begin with.
danted002@reddit
You’d be surprised how much garbage collectors consume/runtimes consume compared to a language that doesn’t have either.
And you are also comparing it with Rust which is good at handling memory efficiently. You
v66moroz@reddit
If you implement Haskell-style FP in Java you will be surprised. If you use OO-optimized data structures? Not that much. As for runtime it doesn't technically "consume" anything, it provides certain functionality (e.g. preemptive concurrency), if you need it you will have to write it in Rust yourself (believe me, it's not that easy, green threads is not the same thing). As for handling memory efficiently? I bet you've never fought with borrow checker, especially if you app is slightly more complex than "try me". Memory management is hard, period, and Rust makes it just a tad easier. GC makes it a way easier, but it has a cost.
caltheon@reddit
Yeah, Rust isn't some magic performance bullet. That would be assembly
kodingkat@reddit
That's what I want to know, could they just have improved the original go and got similar improvements? We won't ever know.
MagicalVagina@reddit
The majority of these articles are like this. They attribute everything to the change of language. While instead it's usually just because they rewrote it cleanly with the knowledge they have now, they didn't have at the beginning when the service was built. And even maybe with better developers.
apadin1@reddit
Tbf if you’re going to rewrite a service anyway, you might as well do it in Rust and get that memory safety bonus
coderemover@reddit
Usually it's both. I did a few similar rewrites and the change of the language was essential to get a clean and good rewrite. Rust is one of the very few languages that give developers full control and full power over their programs. So they *can* realize many optimizations that in the other language would be cumbersome at best (and lead to correctness or maintainability issues).
I've been doing high performance Java for many years now and the amount of added complexity needed to get Java perform decently is just crazy. So yes, someone may say - "This Java program allocates 10 GB/s on heap and GC goes brrrr. It's badly written." And they will be technically right. But fixing it without changing the language might be still very, very hard and may lead to some atrocities like manually managing native memory in Java. Good luck with that.
ven_@reddit
The original source is a presentation the intern in question gave himself. In it he said that improving the existing code base would have been his preferred option but due to the nature of the service he needed tight control over memory which is what ultimately made up the performance gains.
I’m guessing there would have been a way to do the same in Go, but I don’t think Go vs Rust was the point here.
BenchEmbarrassed7316@reddit
go has very bad serialization and deserialization. Either runtime reflection or third-party code generation programs are used. go also has a very bad type system due to nil and default values: if a numeric field in a structure that you are trying to get when deserializing is optional, you will either get 0 both when it is 0 and when it is null (which is a gross logical error) or you are forced to make this field a pointer. If you have an optional nested structure - you get a bunch of unnecessary allocations + unnecessary work for gc. go compiler does very few optimizations (they say it is for faster compilation). In short, a speedup of 2 times seems quite small to me. go is a terribly designed and slow language.
Qizot@reddit
Go is slow? It is faster than majority of languages out there. If you don’t like the language it is fine, but don’t behave like it is unusable garbage since it is not.
BenchEmbarrassed7316@reddit
Sure, go is faster than for example Lua or Ruby. But I'm specifically describing what is poorly designed and slow in a specific use case. Microservices are a bunch of I/O with serialization and deserialization.
theshrike@reddit
I think Twitch or Discord had a similar thing where the millisecond Go GC pauses were causing issues and rewriting in Rust was a net positive.
What people forget is that 99.999% of companies and projects they work with are not working at that scale. Go is just fine. =)
kerakk19@reddit
Yes, Rust is obviously faster than Go but not 4x faster
NyanBunnyGirl@reddit
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-go.html
kerakk19@reddit
That's quite interesting page, thanks
coderemover@reddit
I bet it was also not well written in Rust either. :P
Party-Welder-3810@reddit
Yeah, and maybe show us the code, or at least part of it, rather than just claim victory without any insights.
IntroductionNo3835@reddit
My opinion is simple, I prefer desktop software because it doesn't depend on the web and is faster.
This software thing in the browser, 100% dependent on the web and generally based on interpreted languages, is super slow, a performance disaster and an ecological disaster.
I did tests comparing C+× and python. Python consumed 4x more memory and was 60x slower.
This is totally anti-ecological. It borders on irresponsibility.
Computer sciences need to reflect, as it makes no sense to develop software and systems that are so slow and so dependent on mainframes. The programmer earns a little and the bill for his laziness is paid by the user!!
We fought hard to have computers at home, we bought software and hardware. They were ours, fast, efficient.
Now we are back to depending on mainframes and super slow and insecure systems.
We regress!!
pheonixblade9@reddit
I rewrote some pipelines at Meta and saved more than $10MM/yr in compute. It's really not difficult at the scale these companies operate at if there are low hanging fruit.
90% of efficiency problems are due to stuff like expensive VMs polling rather than having a cheap VM polling, then handing the work off to the expensive VM. Higher level stuff where the language/tech isn't super relevant.
FortuneIIIPick@reddit
The same changes would have worked in Java, C#, or Go if they had wanted to do so. They are clearly into Rust and wanted to appear to be able to justify it. Click bait.
shevy-java@reddit
Rust sneakily conquers the world.
Pharisaeus@reddit
RICHUNCLEPENNYBAGS@reddit
I don't think it's a secret that gains like this are routinely left on the table to save on labor or timeline. Don't get me wrong, $300k is real money, but it's not so huge that that couldn't be a sensible decision for an organization of that size.
ml_guy1@reddit
I think the core reason why developers and ai-agents write slow code is that there is just not any tooling to automatically profile your changes, and then search for the most optimal way to write your code. even after ai generated code, there just does not exist any way to write faster code automatically.
ShovelBrother@reddit
I'm a bit curious to see what the go code before looked like as variable memory usage was sited as a problem to be solved. Was the code already unsafe and using memory arenas?
Peppy_Tomato@reddit
I don't need to read the linked article to guess that the implementation strategy/algorithms were what ultimately mattered, not the language chosen.
zenware@reddit
Yep, without clicking I’m 90% sure that the intern could’ve improved the Go code and achieved nearly identical results.
ldrx90@reddit
I clicked. They claim that any further optimization of the Go code would have been fruitless.
From the article:
I don't know Go or Rust and they didn't provide any coding examples so, just have to take their word for it I guess.
klowny@reddit
I have experience with both languages and have been in the same situation.
By the time you care about performance and doing these kind of optimizations actually makes sense, you'll pick rust every time.
Go is for feature velocity. It's pretty slow for a compiled language, and even more difficult to optimize. It's easier to optimize with rust and you get so much more performance out of it too.
sammymammy2@reddit
Why is Go difficult to optimize?
klowny@reddit
In short, because you can't do much to change the behavior of the garbage collector or bypass it. Or going lower level than Go's primitives, which are not fast.
For many other languages, optimization involves controlling the memory layout and basically writing at a C level. Go does not give that low level access.
So what happens is you end up writing C, then doing all sorts of tricks to translate that C to Go while forcing Go to pretend it is C the best you can, which generally involves a ton of unsafe and raw pointers on every line of code but with none of the tools C or other languages gives to help manage those things all while fighting Go's garbage collector or working around missing primitives.
In most other languages, you can just.. use the C directly with some shims or use it's C level equivalents.
Go written like Go is already at a lower abstraction level than Rust/C++, so it's silly to write even lower level Go code when you can write at a higher abstraction level in Rust/C++ and not have to fight the language the whole time and still get faster performance.
ldrx90@reddit
That's pretty much my assumption as well. It's easy for me to believe they knew enough to judge if squeezing Go was going to really help or not and to make reasonable estimates about how much quicker they could do it in Rust. Then you just make the intern do it and see how it turns out.
BenchEmbarrassed7316@reddit
https://www.reddit.com/r/programming/comments/1okf0md/comment/nmbwkyn/
tldr language matters, golang is slow.
Farados55@reddit
Could’ve just linked to the blog post instead of this rehashed linkedin slop
InfinitesimaInfinity@reddit (OP)
I read several articles about it, and I linked one of them. I did not write the rehashed linkedin slop.
The article written by the intern is here: https://wxiaoyun.com/blog/rust-rewrite-case-study/
Also, I did not write the rehashed linkedin slop.
SureElk6@reddit
if you knew the original link why did you link the LinkedIn post?
are you "Animesh Gaitonde"?
InfinitesimaInfinity@reddit (OP)
No, I am not "Animesh Gaitonde". I did not write either article.
That is a good question, and I do not have a good answer.
i_invented_the_ipod@reddit
Thanks for the link, I'll check this out. I always wonder in cases like this how much of the improvement is "rewriting after profiling", vs "rewriting in language X"...
gredr@reddit
That was exactly my thought. This isn't about Rust, this is about improving the implementation. It could've been FORTRAN...
mcknuckle@reddit
That was my thought as well. There isn't nearly enough information given to know whether the improvements were due to Rust itself, or implementation more specifically, or whether the same gains, or more, could be found using other languages or techniques. The article reads more like propaganda than well thought out technical analysis. It reads like a novice justifying novelty.
fireflash38@reddit
Idk what it is, but I despise the overuse of emojis.
mrjackspade@reddit
Probably AI
youngbull@reddit
Let's understand how they did this in simple words.Yeah, that is the AI regurgitation parts of the prompt.youngbull@reddit
Your linked-in post is leaking your prompt.
InfinitesimaInfinity@reddit (OP)
I did not write the LinkedIn post.
scrollhax@reddit
Is $300k savings supposed to justify the overhead of supporting an additional programming language?
fig0o@reddit
How much would he have saved by just re-writing the software using the same language?
Supuhstar@reddit
Pay that intern $200,000/year
NoMoreVillains@reddit
Because most devs aren't working on systems operating anywhere remotely near the scale or TikTok.
NuncioBitis@reddit
Now they'll have to spend 3x that to fix it over the next 10 years.
EntireBobcat1474@reddit
To play devil’s advocate here - one frequent retort you’d hear is that now TikTok has to retool or hire some portion of their staff to maintain rust instead of go code, which may create more cost. That said, most companies hire generalists, I don’t think there’s a real staffing cost to having to have part of your team train up on rust now (especially if they want to keep doing similar optimizations). I would be worried about potential friction if this was the only rust silo in that org though, since that would create friction when people want to make changes there, until rust becomes more widely adopted, but if that’s already a part of their engineering strategy, then all the better
NYPuppy@reddit
To play devil's advocate to your devil's advocate, learning a new tool is to be expected on a job and isn't a bottleneck. Newer languages, like rust, typescript, go, kotlin are all clean and readable and relatively easy to pick up.
swansongofdesire@reddit
If reports on the internal TikTok culture are accurate, it’s much worse than that: they let devs choose whatever they think is ‘the best tool for the job’, regardless of team expertise. This works out just as well as you can imagine.
Caveat: anecdata. Interviewed there myself, and have interviewed 3 ex-TikTok devs.
Coffee_Crisis@reddit
This is a viable strategy if you have a truly modular system and code can be thrown out and rewritten with confidence
EntireBobcat1474@reddit
Oh yeah that's very different
Xalara@reddit
One thing to keep in mind as well, is that while many developers are generalists, Rust is different enough that it can trip up even generalists.
jug6ernaut@reddit
Generalists is definitely what an avg company should be hiring for. There are definitely places for specialists, in my experience they are few and far between.
As a developer you should always view languages as tools, use the right tool for the problem. Tribalism only limits your career possibilities.
DuckDodgersIV@reddit
And 200K of that was wages!
mmaure@reddit
so how did the interop work?
claytonbeaufield@reddit
For a company the size of tiktok, $300k is quite a paltry sum.
rishiarora@reddit
300K in bill change can just a slight load fluctuation give scale at which Tik Tok Operates.
editor_of_the_beast@reddit
That’s a rounding error for TikTok, isn’t it?
rbadaro@reddit
It's minimal but still valuable. Compute efficiency efforts at companies like this are measure in 100s of millions.
jeesuscheesus@reddit
That intern paid for themselves and then some. For that team it’s quite significant, and that will extend to the rest of Bytedance.
nemec@reddit
It's also really great to have on your resume!
Contrite17@reddit
I mean it isn't huge compared to revenue but it is still a good win. It all does add up, and as long as the labor to do something like this isn't crazy it is well worth doing.
wutcnbrowndo4u@reddit
It's 0.0001% of revenue, "isn't huge" is a dramatic understatement
That being said, it's not like the CEO had to manage this project. At the team level, it's a pretty reasonable amt of cash
Exepony@reddit
All else aside, this intern is going to have one hell of an XYZ bullet point on their resume now.
HistorianMinute8464@reddit
How many pennies of those $300,000 do you think the intern got? There is a reason the original developer didn't give a shit...
CardiologistIcy5307@reddit
Sounds like a great strategy for B2B SaaS companies.
captain_obvious_here@reddit
I rarely read that it's pointless. I most often read that it's not always a high priority. And in a world where new features make or break a company, it makes perfect sense.
nierama2019810938135@reddit
I dont often hear thar optimisation is pointless, but optimisation before it is necessary is pointless.
KFUP@reddit
300000 feels like it has a lot of numbers... until you realize that's just 0.3m, and tiktok's revenue in 2024 was 23b, that's 0.0013% saving of that year. This is more of statement on how gigantic tiktok is rather than how faster rust is than Go, any practically insignificant improvement would seem big.
I guess "An Intern Saves Tik Tok 0.0013% of its Annual Revenue" is not as impressive sounding.
Valkertok@reddit
It's not much from the perspective of entire company.
It's quite a lot from the perspective of value of work of this one (not yet) employee.
horizon_games@reddit
Sounds about right - whenever Go or Node or Python tries to get performant they just try to hook into C++ or Rust to achieve it.
Thin-Yard471@reddit
I understand how you feel. That's absolutely fascinating! Seeing a measurable improvement like that in core metrics—CPU, memory, latency—is the kind of thing that truly shifts perspectives. Makes you wonder what other "insignificant" savings there might be hiding in the benchmarks.
Hear me out, coming from someone who spends a lot of time looking at code performance (often wishfully):
Profiling first.
That's my cardinal rule for optimization work. Before I get excited about "making the code faster" or suggesting a rewrite, my immediate reaction is always: "Okay, where are we hitting these bottlenecks? Can we measure the impact?"
Because here's what often happens: People hear "optimize this code" because it might take slightly longer in some edge cases, or maybe the garbage collector does a pause somewhere. But you're literally seeing power-of-two performance improvements on critical, CPU-bound workloads.
ven_@reddit
As a comparison, saving $300k on a 500 million dollar cloud bill is like saving $60 on a $100k cloud bill. That’s pretty pointless if you ask me. It’s just that these companies operate on scales that are difficult to fathom.
Flagtailblue@reddit
Imagine how much $$$ if C or asm! 🤯
Sunscratch@reddit
Or from simply removing this API’s!
Harteiga@reddit
You also have to keep in mind that TikTok has an insane amount of traffic. A startup or even most decently sized companies would not see the same return
Sunscratch@reddit
Yep, for TikTok scale, 300k per year is a joke. But the nice thing about Rust - it’s easy to pitch it for management: you can convert Rust benefits into real money, something that managers do understand.
Jaded_Ad9605@reddit
No... Premature optimization sucks. If you know what's the bottleneck you can fix THAT
IkuX2@reddit
Maybe I’m autistic but seeing my boi Golang got rewritten into Rust hurts a little bit lol
DocMorningstar@reddit
That means TikTok is insanely profitable, or insanely poorly run. 300k a year in pure profit(!) For a small, discrete, identifiable optimization and its done by...an intern?
Either the 'real' devs are out there spending time on millions per-year in profitable changes, or noone is looking at efficiency, and this was just a 'get out of.my hair, kid' project
VehaMeursault@reddit
If you save 300 big ones by reducing your compute, you’re already big enough for 300 big ones not to matter that much.
If it did, then your code wasn’t suboptimal; it was terrible. Which would be a whole different problem to begin with.
carl_peterson1@reddit
SMH intern could have had 15 codex agents generating 25,000 lines of typescript in the time they took to write their little baby microservice
i860@reddit
Go is not slow per se but it’s not fast either. Passing arguments and return values for everything via the stack is naive and no modern compiled language should be doing this.
funny_falcon@reddit
Actually, modern Go compiler uses registers for calling convention in Go-to-Go calls. It still uses stack for Go-to-ASM though.
Days_End@reddit
Are you sure your not missing a 0 in there otherwise it seems like a pretty big waste of time.
Kozjar@reddit
People say it about CLIENT optimization specifically. TikTok doesn't care if their app uses 15% more CPU on your phone than it could.
LanguageSerious@reddit
He got nothing in return I presume?
token40k@reddit
I saved 5mln annualized single-handedly enabling intelligent tiering on 20k of buckets with 60pb of data. 300k a year save sounds like a fix for something that should not have happened to begin with
FoldLeft@reddit
ByteDance may use Rust in other areas as well, they have a Rust port of webpack for example: https://rspack.rs/guide/start/introduction.
DoubleThinkCO@reddit
Dev salary plus benefits, 300k
phoenix823@reddit
I’m curious how, or if, they thought about the incremental cost of adding a new language to the code base. Obviously, they were able to realize a meaningful operational save by making this change, but now they have the added of complexity of Rust in their environment.
KingNothing@reddit
Why is this interesting? Throw a dart at the arch diagram of any medium to large company and you’ll probably hit a similar opportunity.
cto_resources@reddit
I strongly doubt the improvements came because the language changed. When a developer goes in to optimize, they can get great results by optimizing the algorithms. The language only matters a little.
My guess is that if the exact same developer had optimized the exact same service, but left it in Golang instead of converting to Rust, the dramatic improvements would have been seen. Because she/he optimized the algorithms.
apoleonastool@reddit
300k is peanuts. It's a fun exercise for an intern, but the company won'tceven notice it.
bigtimehater1969@reddit
A lot of this is just "impact"-bait. None of this work helps Tik Tok's business in any way, and $300,000 is probably a drop in the bucket (notice how every number has a before and after except for the cost. It's probably like a small company rewriting code to save $3).
But you see $300,000, and you see numbers decrease, and you get impressed. This is how you chase promotions at big companies - find busywork that results in impressive metrics. What the metrics measure is irrelevant.
Traditional_Pair3292@reddit
I work at a Faang company and I saved $1m per year changing one line of code that was doing a full recursive file search every 5 seconds. When you have these massive scale companies it’s not hard to do
fagenthegreen@reddit
Worth noting that $300,000 per year is basically a rounding error compared to TikTok infrastructure.
Coffee_Crisis@reddit
The important parts here are that this service was identified as an actual hotspot in a system that is as scaled as can be, and the solution was a change to a different class of language, and the savings was only $300,000. This is a good intervention for TikTok but if you’re not at that scale you will probably be have a negative ROI if you are paying a dev to do stuff like this rather than just provisioning more capacity
lilB0bbyTables@reddit
Alternative title - massive and successful company decides to pay off technical debt accrued while building out from startup phase.
Any startup out there is operating on borrowed time, and the goal is to manage technical debt in a deliberate and strategic way. If you have engineers spend time hyper-optimizing everything constantly and refactoring everything constantly they will stagnate and fade into obscurity. Of course if they don’t manage technical debt properly then they risk hitting increased friction while iterating on new features, or they hit severe and unexpected limitations of scaling as they grow and begin burning cash at faster rates. Finding that balance is the key to success
bunoso@reddit
I also rewrote my api server in rust. It now saved me 100% of my bill. I was paying $0 for 10 lambda invocations a months and now I pay $0. You’re welcome.
PuzzleheadedPop567@reddit
This makes sense to me, reading the linked in post. Once you reach high QPS in a microservice architecture, you spend a lot of resources on serialization, encryption, and even thread hops.
Big tech companies like Google and Amazon have entire teams working on these problems.
1) More and more encryption has been pushed down into the hardware layer.
2) A recent area of research is “zero-copy”. As in the network card reads and writes to an OS buffer that is directly accessed by the application. This eschews the naive / traditional pattern where multiple copies of the req/resp data takes place, even if the Python or Java application developer isn’t aware of it.
3) I’ve optimized high QPS services before, and thread hops due make a difference. Programmers in higher level languages probably don’t even realize thread hops take place. Go has virtualized threads, so you can’t control when the runtime will decide to transfer work between different OS threads. Languages like Rust and C++ are useful because you can control this. I’ve written services that avoid ever handing work off between OS threads. Even a single context switch noticeably impacts performance and cost.
13steinj@reddit
Something super interesting along these lines here-- Google, the service, is to my knowledge written to be as efficient as possible. I mean, it makes sense. Every byte transferred over the wire is done to millions of people, cost of scale kind of thing.
Every single developer doc page I've ever visited? Feels like I just downloaded a youtube video or something. If you check, you'll see that each dev site like google dev docs or bazel.build all end up downloading 0.3 to 0.7 gigabytes to store in your browser cache/data, each time you visit them.
tangoshukudai@reddit
no no, they saw some bad code was costing them a ton of money and they fixed the bug.
shotsallover@reddit
I’m guessing the intern got a $100 bonus and vague promises that they might get hired in the future.
cjthomp@reddit
Bullshit, "premature optimization" ≠ "optimization"
qckpckt@reddit
This could easily be used as an argument to say that optimization is pointless. $300k a year is nothing to a company like TikTok.
They probably get multiples of that every year in free compute credits as incentives.
In a perverse way these kinds of optimizations could even be bad for a company. I worked at a place where AWS paid the wages of some contractors that we employed to deliver new tenants on our platform.
When we made the platform significantly more efficient, AWS complained loudly that the projected costs of their sponsored project were below their estimates, and ultimately stopped covering the costs of the contractors.
Unless you add at least one more zero to cost savings like this, no company will give a shit.
Smok3dSalmon@reddit
I did something similar in my first job by pre-allocating a 2MB buffer on application start and reusing it. The buffer was used to store rows of data in a database query. It reduced cost by 90% for batch database processing. The software had a wonky business model where they charged based on hw utilization. So they lost money. LUL
Perfect-Campaign9551@reddit
Um, any developer that "claims" optimization is pointless.. Is a moron, and obviously not very skilled. Because most of the time, optimization is not that hard to do
Santarini@reddit
Just to clarify the primary source for this "news" is a LinkedIn post?
InfinitesimaInfinity@reddit (OP)
The intern wrote an article at https://wxiaoyun.com/blog/rust-rewrite-case-study/ .
Santarini@reddit
Yeah I saw that. Intern claims he did something remarkable on his own blog.
... Then why is he only an intern? You don't think TikTok would have offered him a full time position after having such significant impact in such a short period of time?
thisisntmynameorisit@reddit
At big tech these numbers are not extremely significant. This just sounds like a decent intern project that some TikTok team supported them on.
PatagonianCowboy@reddit
He's still studying so maybe can't become a full-timer, who know
Santarini@reddit
Maybe. But Occam's Razor and a healthy suspicion of Internet facts has made me skeptical of self-acclaimed, unverified success
heraldev@reddit
the post sounds like typical performance review impact fluff. congrats, somebody got a promotion (or return offer in this case)
tankmode@reddit
this is why i find the layoff trend so short sighted. most decently planned software development work builds more value than it costs. its poor management thats the problem for most of these businesses and layers and layers of management
Omni__Owl@reddit
If we always wrote optimized code we'd likely still be on quad-core processors.
StarkAndRobotic@reddit
It doesnt take a genius to optimise, just time. Sometimes because of higher priorities or lack of time, some basic code is written so the job gets done, even if its not the most efficient.
PurpleYoshiEgg@reddit
I doubt these weasel words.
caiteha@reddit
I used to use Java for services, now I write everything in C++ ... I can tell the differences ...
White0ut@reddit
300k in computing cost over a year is a drop in a bucket for TikTok. You could go clean up unused test/dev servers once a week and save that much.
Matt3k@reddit
Then maybe someone should do that?
White0ut@reddit
We did once in a while, but nobody really cared.
this_knee@reddit
Per year? … they saved only after the first year. After that it turns into just operating cost. Unless each and every year they made updates that made it better and better and saving more and more money every year.
wutcnbrowndo4u@reddit
Per year is relative to the counterfactual in which the previous server was unoptimized
Matt3k@reddit
My industry is completely borked. But thankfully, I've got years of experience working hard labor in the bitmines and can value myself accordingly. I guess there's a silver lining.
balianone@reddit
tiktok > google/alphabet
BlueGoliath@reddit
By "developers" you mean "high IQ" people on Reddit mostly.
No way. Tell me more.
PatagonianCowboy@reddit
People should rewrite in Rust more often
LessonStudio@reddit
There are those who will want you burned at the stake.
Until you do something familiar in rust, you just don't realize what the hell it is. I think most C and C++ people see it as doing pointers really carefully and think, "What's the big deal? I don't even like smart pointers."
But, every company I know using rust is basically, "We could not do what we do the old way. Not even close." the tech debt is accumulating at a snail's pace, the productivity is through the roof, and stays there right up to the end, and the bug count is more often someone misinterpreting a requirement or a bad design, than the usual threading, memory, or other errors people make when doing the dance of the seven veils with pointers. Those basically go away with rust.
Then, there are the little things like handling the wonderful results to completion, instead of going, "Ya ya, those other things never happen anyway."
And on and on.
The expression "If it compiles, it probably works" is so very true with rust. But the C/C++ crowd say moronic things like, "If you just don't make mistakes, you don't need a crutch like rust."
I remember a story about some moron manufacturing consultant who was hired by a factory. He asked the floor workers, "Can you make one widget in a row correctly?" "Can you make two in a row?" and so on. He then said, "Focus on doing that over and over, and mistakes will just fade away." Total garbage.
Instead, the correct approach is to pretty much drop what everyone is doing when a mistake happens and try to figure out the root cause. Often there is a process or even tooling change required to prevent this mistake again. They don't see them as crutches, but a method for higher quality products. Rust is just the tool which looked at the sources of the problems and started eliminating them. C/C++ keep looking at more complex ways to screw up your code even worse. Let's add rare and obscure template constructs so that nobody but a few pedants can understand the code, and even the, only after intense study.
kapybarah@reddit
I'm sure everyone tries to optimize as best as possible the code that runs on rented hardware. Maybe some client side code can be less than ideal in terms of performance for certain types of application because of 'how fast computers are' but even that is only somewhat true because users expected things to be fast, ironically, because computers have become really fast.
Also just because it was done by an intern doesn't inherently mean it was simple or easy. They could very well be an excellent dev already
Gibgezr@reddit
And, of course, they would have gotten the same speed-up from rewriting in.
heatlesssun@reddit
He probably ran it through an AI because the other folks were to arrogant to try.