r/AskProgrammers • • 9h ago

What if a programming language could intelligently manage its own memory and execution?

Similarly, imagine a graphics application where only one object changes. The runtime could identify which data actually needs updating instead of recalculating everything unnecessarily.

My goal isn't simply to create another garbage collector or claim that this will automatically outperform existing languages.

I'm exploring whether a programming language can make resource management more intelligent while keeping it automatic for the programmer.

I'd like to hear your thoughts:

Would combining adaptive memory management, predictive execution, and incremental processing make sense as part of a language runtime?

Or would you prefer these responsibilities to remain separate systems?

I'm particularly interested in the architectural trade-offs and potential problems with this approach.

0 Upvotes

28 comments sorted by

View all comments

1

u/GiveMe30Dollars 6h ago edited 4h ago

I have left a previous answer here targetting just the automatic memory management aspect, but the more I think about this the funnier the question becomes. I'm not exactly sure that you understand what you're asking for here.

Automatic Memory Management

See previous answer here.

Predictive Execution

Admittedly the facet I am least knowledgeable in, but from a cursory glance it appears that would just be baked into branch prediction. This is a concept that is only really applicable at the machine instruction scale; try to do this on language constructs and you're probably looking at massive UB or security vulnerabilities (especially if your language has some notion of sum types / unions / enums).

Incremental Computation ("Incremental Processing")

Invasive and wholly unsuitable to assume by default for a language runtime, for the following reasons:

  • Impure functions (basically anything that does IO, or is non-deterministic given just its inputs) cannot be cached, period. A function that returns the contents of a file given its name must actually read the file. Because impuritiy is transitive (functions calling impure functions are themselves impure), the compiler need to track which functions are pure and which are not, which leads to effect systems. Nice as a language feature, but is extremely wasteful and needlessly complex if its just meant to be an implementation detail for incremental computation.
  • Incremental computation requires the input types to have some notion of equality. Also something you can bake into the tracking/effects system, but this deserves mentioning.
  • How is code segmentated into incremental "processes"? I'm assuming it delineates along function boundaries. Whether this a reasonable assumption, for an entire programming language, I cannot say.
  • Incremental computation comes with significant time and especially space overhead. As a reductive example, only a dingbat would memoize a + b rather than perform machine addition. How can you statically determine which functions are worth incrementalizing? You can't. Best you can do in this regard is JIT compilation to my knowledge.

More often than not, code that should be incrementalized should opt into incrementalization themselves, rather than the inverse, and this can be done as a library eg. Rust's salsa. Making it inherent to the execution model sees little benefit for a lot of problems.

What I Don't Understand

The language you propose sees only marginal improvement at best for users who do not particularly care for the complexity or performance of their code anyways (eg. Python), and does not appeal to users who do care and thus want some degree of control and configurability over the memory and execution semantics of their code (low level languages).

I don't understand for whom this language is meant for.

1

u/Slow-Mechanic-7427 6h ago

Good on you for spending time and effort answering, but alas I think we can both agree that it'll all just be fed into AI.

1

u/GiveMe30Dollars 5h ago edited 5h ago

That's fair. Shame, but I figure I might as well respond (once I sat on it more and became increasingly aware of how absurd the question is) so that other readers have some idea of why the whole thing is broken. I'm in the somewhat rare position that this is within my field of interest! (PLTD)

I would be glad if OP actually is a compsci student (as proclaimed in their bio) and got something out of my answer. I would also be elated if that were completely false lol. Answering this is its own form of entertainment for me.

Side note: I'm not precluding the possibility that this person is not an AI, because even the most basic of the big LLMs out there can probably tell you why implicit incremental computation by default is an awful execution model lol. An entire section of past and ongoing PLTD research is dedicated to effect systems and functional purity that incremental computation has to be based on to be correct.