Hacker News new | past | comments | ask | show | jobs | submit login

Not always. Sometimes it’s annoying to do something performant in assembly but trivial in a higher-level language: hashmaps, for example.



The main advantage of Asm is the tiny constant factor. A linear or quadratic algorithm can beat a logarithmic or even (amortised) constant-time one on the sizes of data used, if the latter has a much larger constant factor.

Just like in a HLL, if you really need it you can still write reusable data structure libraries, but Asm's really tiny constant factor and effort involved in adding complexity forces you to think about whether you really need it first.

In other words: in the amount of cycles spent initialising a hashmap and inserting a few dozen or hundred items (perhaps involving memory allocations, etc.) just so you can get (once again, a relatively large factor each time) asymptotically constant-time lookup in an HLL, you could've gone through the whole set many times already in a tight loop of less than a dozen instructions, that entirely fits in the L1 cache along with the data too.


What are you talking about? You're talking about implementation. This has nothing to do with assembly at all. Assembly is not a magic language that offers instant efficiency. 'Constant factor' is entirely irrelevant to this discussion. There's nothing stopping an engineer from implementing equally inefficient data structures/algorithms in assembler as they would in a higher-level language. It is true that if the engineer understands the problem domain very well, and the project requirements are amenable, the possibility certainly exists for them to solve the problem with highly efficient assembly. This is true for almost anything. However, it exists at the cost of extra development effort with no real guaranteed benefit.


There's nothing stopping an engineer from implementing equally inefficient data structures/algorithms in assembler as they would in a higher-level language.

...except the additional complexity of doing so? If you have to write every single instruction, you start thinking more about whether you have to write each one.

'Constant factor' is entirely irrelevant to this discussion.

It's entirely relevant to the real world.


Division by constants is another example.

C compilers will convert constant divides into reciprocal multiplication. All the handwritten assembly I have seen uses the divide instruction.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: