News for hackers. Stuff that matters.
Re:Six times faster than C by arun-mani-j on Friday July 07, 2023 @03:28AM (#36628388)
Any guide on how a person who uses Python or JavaScript can learn such things? I mean knowing which assembly code would be better, which algorithm makes better usage of processor etc.? :)

Also, how is such optimization carried out in a large scale software? Like, do you tweak the generated assembly code manually? (Sorry I'm a very very very beginner to low-level code)

Re:Six times faster than C by sigmoid10 on Friday July 07, 2023 @03:37AM (#36628470)
You do this by first learning C (or similar languages) and then compilers and maybe also operating systems. What you're seeing in this blog is the equivalent result of at least one or two years university level education, so it's not like there is a single book or tutorial you could use to get you up to speed, especially if you have no previous experience in that area. And building a better compiler optimisation in general is a PhD thesis level task. But it's also not necessary if you want to design user applications on today's hardware.
Re:Six times faster than C by dottedmag on Friday July 07, 2023 @03:34AM (#36628441)
* * *
Re:Six times faster than C by secondcoming on Friday July 07, 2023 @06:50AM (#36629830)
You learn by doing. Compiler Explorer [0] is fantastic for this sort of thing. Typically you would do this sort of optimisation after profiling and then on a per-function level.

[0] godbolt.org

Re:Six times faster than C by 414owen on Sunday July 09, 2023 @03:06PM (#36657790)
This is pretty much `assembly language the game`: https://tomorrowcorporation.com/humanresourcemachine

It's not a useful architecture, but it teaches the thought process really well, and you end up discovering a lot of optimization naturally.

For this article, I'm measuring every step to see what the performance implications of the changes are, which, along with some educated guesses and some googling/reading other articles, was enough for me to figure out what was going on.

In part two (https://owen.cafe/posts/the-same-speed-as-c/) especially, I didn't know what was going on with the benchmarks for a long time. Eventually I got lucky and made a change, which led to a hypothesis, which lead to more tests, which led to a conclusion.