Hacker News new | ask | show | jobs
by switchbak 17 days ago
I often wonder how much benefit we get from most of those optimizations. I rarely felt that Turbo Pascal's runtime was slow or slow enough to cause frustration over something like C.

I think we could do something similar today - very fast compilation, and straightforward but efficient machine code. And perhaps bolt on the heavy duty optimizations where it is needed. Many JIT's work similar to this, but it seems like you could do it in an AOT style too.

3 comments

> I often wonder how much benefit we get from most of those optimizations

Well, in a world where many among most used apps are made of NodeJS and Electron frontend, I think we are very far away from having to worry about those optimizations in most contexts. Having those written in TP with zero optimizations would still be more resource efficient and performant.

And when it comes down to squeezing last drop of performance, we forget compilers and still rely on assembly wizards tuning BLAS routines, crypto code etc.

Not to mention all of the superhuman efforts that chip makers take to make existing app patterns (typically driven by C) perform acceptably.

It does make you wonder how much we could simplify and take away while still having things be blazing fast. I would assume some of the old optimizations are actually hurting things on newer architectures.

Yup IMO there's a sorely missing space for a language with very low-level capabilities which doesn't rely on auto-optimisation. C++ is only relatively fast because of the insane amount of optimisations the compilers have + compiler -specific directives.

But I mean more like

- being able to explicitly tell to unroll this loop N times

- native support for builtin SIMD vector types (it can use platform-dependent instructions, whatever)

- specifying aliasing manually, built-in support for range types

- having explicit control over switch statement code generation

- good metaprogramming (doesn't matter if compile-time maths doesn't exactly match runtime behaviour), compile-time code generation/modification

- [[likely]] hints but actually respected i.e. having a guaranteed effect on code layout

- of course no headers, the unit of compilation being a whole library

I don't think it really needs to be single-pass in order to be fast, just cut out most of the heuristic-based optimisations from the backend and make them explicit keywords/attributes in the code...

I think this is one of the "paths not taken" already. The economy of making software (by people) voted in favor of "sufficiently smart compiler" with profile guided and link time optimizations. It happened a long time ago and most of the code that I have worked with is structured to require such a smart compiler. The early examples of half codebase in assembly like Photoshop 1.0 in the public archive were clearly more expensive to make for a single platform - not to mention how many platforms people need now to recoup development costs.

What you are describing is what Zig spent years to try to become while running away from LLVM. Sure thing there are other less popular attempts which I can't even bother to list here, not because they are somehow worse, but because they are even further away from gamedev practice that I care about.

I don't know what the economy of generated code would be. It is up for debate right now.

What I can definitely see now is that human-only code made this way is not going to pay off. It can only be an expense for someone who has unlimited budget to spend on a whim.

Yup I'm very much aware of path dependence, and that rewriting code has a huge cost. But we have AI now, so it can definitely be slopped out fairly easily....
You're describing Go. Only difference was Go settled on GC, to avoid alot of semantic complexity with memory management across threads.
Go would be nice if they didn't ditch stuff that was already present in Pascal (proper enums, sets, variant records/unions).
Spot on, that ridiculous iota/const boilerplate "best practices" pattern.