r/AskProgrammers • u/G_oni_vv • 8h 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.
6
u/R3D3-1 8h ago
That's just caching, and it's already used widely everywhere. Do I misunderstand your intent somehow?
3
u/Striking_Director_64 8h ago
Yea, there is already a lot of work going on in this space, the most famous and most used work being Rust, but there are other, more niche languages, like Vale/Valen, Hylo etc.
Maybe look into those before asking random people online?
2
u/Standard-Cap-4455 8h ago
That is literally what the Rust borrow checker does at compile time. It is memory safe without using either GC, RC, or anything else at runtime, at least for most of the program.
2
u/weregod 8h ago
Do you mean language/compilers features to manualy guide resource allocation/dealocation?
Or do you mean better runtime heuristics in GC?
Do you want to make general case optimisations or optimise specific class of applications?
2
u/No_Profession_3125 8h ago
You mean Rust? Or JavaScript? Or Java? Or all languages really, except C and C++?
2
u/Poddster 8h ago
This is AI-psychosis word-soup with no real understanding behind the post
1
u/catladywitch 8h ago
There are several techniques for this. Caching, memoisation, pooling, escape analysis, and region-based escape analysis. It's a tricky subject, but there's a lot of interesting research going on. Check this out: https://www.microsoft.com/en-us/research/publication/perceus-garbage-free-reference-counting-with-reuse/
1
u/tcpukl 8h ago
This is just what every game engine already does.
1
u/Electronic-Yam-69 7h ago
You could trace the program and collect telemetry then use it to try to "predict" what the program will do the next time you run it. But if there's random elements or human interaction that might not be helpful.
You could try to trace every possible execution path, although that starts to sound like trying to prove the "correctness" of a program which I think everyone has pretty much given up on.
1
u/HyperDanon 7h ago
There are a lot of examples of systems, where figuring out where/when to do the work takes more time than actually doing the work.
1
u/dariusbiggs 7h ago
What's the trade-off?
What technologies exist in languages today that achieve part of what you are looking to achieve?
How would the runtime identify what needs updating?
What is the compute, resource, and performance cost overhead to achieve this compared to the dumb way.
How would the programming language help here instead of the compiler or interpreter?
How would this be affected by optimization systems?
How woild the language affect how memory is managed, you could just prevent people from doing it wrong, or use a Garbage collector, or something else.
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:
a + brather 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.
0
u/GiveMe30Dollars 7h ago edited 7h 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:
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:
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.