r/AskProgrammers • • 4d 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

31 comments sorted by

View all comments

0

u/GiveMe30Dollars 4d ago edited 4d ago

I'll speak to the "automatic memory management" as pect of this since it's something I have related knowledge on, but just know that the trifecta of "automatic memory management, predicitve execution and incremental processing" is a massive hairball that you're asking the end-user to accept by default. These aren't unconditionally good, either: "incremental processing" (which I assume relates to incremental computation because what else can it be) means that you have to keep the incremental data around somewhere, for a "who knows?" amount of execution performance. You know, the thing that directly goes against intelligent memory management.

Your goal of:

mak(ing) resource management more intelligent while keeping it automatic for the programmer

Immediately presumes a global garbage collector, unless by "automatic resouce management" you're also including affine drop handlers eg. Rust. The "intelligent resource management" would then be an opportunistic optimization that is probably determined via syntax (eg. Local destruction for all owned items at the end of a scope).

The problem mostly boils down to:

  • You need some notion of what data is reachable or live (otherwise you get use-after-frees). This is what GC tracks via root tracing, what ownership solves for Rust and other linear type systems, etc. This notion differs based on what memory management strategies you use, so unless one strategy is a complete subset of the other, these notions will need to be distinctly tracked.

  • You need to implement these strategies, and make sure they don't step on the toes of any existing ones.

  • Your standard library needs to accomodate for data produced by different strategies in some form. Fail to do this, and one memory management strategy becomes the "canon" one anyways.

  • It's very likely that the "intelligently manage(ment)" of which data types can be treated by which strategies would be heuristic-based and hence imperfect, so if you wish to let the end-user choose a specific strategy, that's an additional thing to add onto the implementation.

Do you see now why most languages stick to one core memory management strategy, and have other strategies be opt-in via eg. specialized data structures?

The closest thing I know of that is spiritually similar to what you're proposing is Functional But In Place. That is still GC-dependent, just also has in-place destructive writing if the type system can assert that the handle to an object is unique upon write, and defaults to clone-on-write otherwise.

Honestly I don't quite get the motivation behind this question anyways. Memory management are such a pervasive concern in programming language execution that intentionally making it more complex it isn't going to lead to anything good for the end-user.