digitalmars.D - Discussion about deprecating nogc and workarounds
- solidstate1991 (24/24) Sep 06 A lot of people are arguing (especially on Discord) that `@nogc`
- Quirin Schroll (3/5) Sep 06 My only beef with `@nogc` is that too many parts of Phobos aren’t
- jmh530 (4/6) Sep 06 If they want to use betterC, why not just let them use betterC?
- Sergey (3/11) Sep 06 Actually the point was to kill both :)
- monkyyy (7/10) Sep 06 Until dlang has several explicit full time mantainers for
- Johan (8/15) Sep 06 May I remind people that one of dlang's big sponsors is Weka,
- claptrap (26/28) Sep 06 For real time audio the actual audio processing will either be in
- Kapendev (8/10) Sep 07 I am fine with how things are, but here are some ideas.
- Lance Bachmeier (12/15) Sep 07 How do you replace this code with BetterC? Answer: You don't.
- Richard (Rikki) Andrew Cattermole (16/34) Sep 07 Just because you lose access to almost all of druntime and phobos does
- Lance Bachmeier (13/49) Sep 07 On run.dlang.io:
- Richard (Rikki) Andrew Cattermole (5/62) Sep 07 Well yes, I have not published it for others to use so far.
- Kapendev (5/20) Sep 07 You just don't use `@nogc`.
- Kapendev (5/30) Sep 07 And if you are unsure if a function allocates with the gc, you
- evilrat (13/44) Sep 07 @nogc is a viable option for optimizing hot paths, in some cases
- claptrap (4/14) Sep 08 And test every function you call, and every function that
- monkyyy (8/24) Sep 08 IFF d had a full time embedded and wasm std dev, and a backlog of
- Sebastiaan Koppe (10/13) Sep 07 Same can be said for every other attribute, let's get rid of all
- Paolo Invernizzi (3/6) Sep 07 Please, just a big no.
- solidstate1991 (5/5) Sep 07 Some introspection:
- Dukc (25/29) Sep 09 Putting my thoughts without having looked at other replies first. No
- monkyyy (5/38) Sep 09 as far as I know theres only 3 ways to care about betterc; and
- Walter Bright (14/14) Sep 09 gc is a "stop the world" gc, but it can be managed in a real-time enviro...
A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC. Here are my thought on the subject: - When it comes for the standard runtime and library, for the most part, yes, but maybe keep around ` nogc` for the occasional student that wants to get into real-time stuff like audio development early on, as an option. - Due to (a world stopping) garbage collection is interferring with real time applications, my solution for that are community-driven runtimes for each target application, many of which already exists. My only concern with the latter is, that people could pull yet another case of D1/Tango, if some people are really stubborn about doing everything their own way, thus stuff have to implemented multiple times. While competition can be a good thing and lead to multiple choices of the end user, it can lead to self-sabotage. On the other hand, people can just fork each others code then refine them to the target runtime. I'll look into some of those already existing runtimes, then think about how should I proceed, as I decided I would need something custom for game development. Came to D because I didn't want to bother with header files in C/C++, stayed because alternatives like Rust and Zig have their own issues, and I'll stay because I want to believe in the future of the language.
Sep 06
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC.My only beef with ` nogc` is that too many parts of Phobos aren’t ` nogc`-compatible even if they can be in principle.
Sep 06
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC.If they want to use betterC, why not just let them use betterC? If you want to use D features not in betterC, then nogc is helpful, no?
Sep 06
On Friday, 6 September 2024 at 13:05:15 UTC, jmh530 wrote:On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:Actually the point was to kill both :) Because it make harder for internal things in compilerA lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC.If they want to use betterC, why not just let them use betterC? If you want to use D features not in betterC, then nogc is helpful, no?
Sep 06
On Friday, 6 September 2024 at 13:11:41 UTC, Sergey wrote:Until dlang has several explicit full time mantainers for supporting for every new arch, killing nogc would make the shit situation of broken and pretend support of embedded and wasm completely unthinkable. D will not be getting the man power for that, so nogc needs to staynogcActually the point was to kill both :) Because it make harder for internal things in compiler
Sep 06
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC. Here are my thought on the subject: - When it comes for the standard runtime and library, for the most part, yes, but maybe keep around ` nogc` for the occasional student that wants to get into real-time stuff like audio development early on, as an option.May I remind people that one of dlang's big sponsors is Weka, where ` nogc` is used extensively to achieve high performance where it matters, in combination with less performance-critical code that is allowed to use the GC. D is used by serious companies, not just students. https://www.reuters.com/technology/data-platform-firm-wekaio-notches-16-bln-valuation-after-lastest-funding-round-2024-05-15/ -Johan
Sep 06
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC.For real time audio the actual audio processing will either be in an OS callback, or a host callback in the case of a plugin. In both cases the "audio thread" will be an external thread that D runtime does not know about. And the only actual code that needs to be nogc, (and no malloc etc), is in that callback. Just the actual audio processing code, well maybe some others in a plugin situation, stuff like events, automation will typically be delivered in the real time thread. So you don't need the whole app to be nogc, just the real time parts, and they will typically be less that 10% of the codebase. So the "lets just remove the GC completely", or "just use a custom runtime", might be a good solution in some cases, but its a sledgehammer to crack a nut solution for others. And tbh I don't see what it fixes? The problem, or what people are complaining about is that trying to make everything nogc compatible puts a burden on people who don't care about it. You don't need a custom runtime to fix that problem. You just need to stop trying to make all the things nogc compatible. If it adds no baggage / burden to GC users then sure fine, but just accept D is a GC language, some of its core language features rely on GC, some of the stdlib will use GC. I don't see massive amounts of posts from people complaining that this or that in the stdlib isn't usable in nogc code? Maybe its not a problem that needs fixing, or maybe ogc people expect to have to do some extra work themselves.
Sep 06
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC.I am fine with how things are, but here are some ideas. I am OK with removing ` nogc` because it's annoying to use and a bit useless. It kind of forces you to take a side, even though nogc code can work with gc code. BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.
Sep 07
On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On 08/09/2024 1:06 AM, Lance Bachmeier wrote:On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:Just because you lose access to almost all of druntime and phobos does not mean you cannot replace almost everything. ```d module app; import sidero.base.console; safe nothrow nogc: void main() { writeln(add(3, 4)); // 7 } int add(int x, int y) { return x + y; } ``` So far the only thing I haven't been able to find a solution for when needed is exceptions in terms of niceness.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On Saturday, 7 September 2024 at 13:28:39 UTC, Richard (Rikki) Andrew Cattermole wrote:On 08/09/2024 1:06 AM, Lance Bachmeier wrote:On run.dlang.io: ``` onlineapp.d(1): Error: unable to read module `console` onlineapp.d(1): Expected 'sidero/base/console.d' or 'sidero/base/console/package.d' in one of the following import paths: import path[0] = /dlang/dmd/linux/bin64/../../src/phobos import path[1] = /dlang/dmd/linux/bin64/../../src/druntime/import ``` Searching on code.dlang.org: Found 0 packages. So not much of a replacement.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:Just because you lose access to almost all of druntime and phobos does not mean you cannot replace almost everything. ```d module app; import sidero.base.console; safe nothrow nogc: void main() { writeln(add(3, 4)); // 7 } int add(int x, int y) { return x + y; } ``` So far the only thing I haven't been able to find a solution for when needed is exceptions in terms of niceness.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On 08/09/2024 2:39 AM, Lance Bachmeier wrote:On Saturday, 7 September 2024 at 13:28:39 UTC, Richard (Rikki) Andrew Cattermole wrote:Well yes, I have not published it for others to use so far. But anyone could do this, its not that hard to wrap printf, which is still available to you if you use -betterC. https://github.com/Project-Sidero/basic_memory/tree/mainOn 08/09/2024 1:06 AM, Lance Bachmeier wrote:On run.dlang.io: ``` onlineapp.d(1): Error: unable to read module `console` onlineapp.d(1): Expected 'sidero/base/console.d' or 'sidero/base/console/package.d' in one of the following import paths: import path[0] = /dlang/dmd/linux/bin64/../../src/phobos import path[1] = /dlang/dmd/linux/bin64/../../src/druntime/import ``` Searching on code.dlang.org: Found 0 packages. So not much of a replacement.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:Just because you lose access to almost all of druntime and phobos does not mean you cannot replace almost everything. ```d module app; import sidero.base.console; safe nothrow nogc: void main() { writeln(add(3, 4)); // 7 } int add(int x, int y) { return x + y; } ``` So far the only thing I haven't been able to find a solution for when needed is exceptions in terms of niceness.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On Saturday, 7 September 2024 at 13:06:45 UTC, Lance Bachmeier wrote:On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On Sunday, 8 September 2024 at 00:10:05 UTC, Kapendev wrote:On Saturday, 7 September 2024 at 13:06:45 UTC, Lance Bachmeier wrote:And if you are unsure if a function allocates with the gc, you can always test. In my experience, if you don't use the `~` operator, array literals or delegates, then you are fine. Just an idea. As I said, I am fine with how things are now.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On Sunday, 8 September 2024 at 00:18:53 UTC, Kapendev wrote:On Sunday, 8 September 2024 at 00:10:05 UTC, Kapendev wrote:nogc is a viable option for optimizing hot paths, in some cases at least. First you profile to find where your code is doing most of the work, then you start from the bottom by adding nogc step by step on such performance hungry functions, it will also enforce changes to these functions from making spontaneous changes. Sure there is also -vgc flag that will show you everything, but often only hot paths is all you need. But like was already said people often tends to use it as a hammer to smash everything, and then they suddenly find out this does not scale or not even work, or solves the problem they never had.On Saturday, 7 September 2024 at 13:06:45 UTC, Lance Bachmeier wrote:And if you are unsure if a function allocates with the gc, you can always test. In my experience, if you don't use the `~` operator, array literals or delegates, then you are fine. Just an idea. As I said, I am fine with how things are now.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.BetterC is weird, but it does do something. If ` nogc` were to be removed, BetterC could act as a replacement for those who want to avoid using the gc and enforce that at compile time.How do you replace this code with BetterC? Answer: You don't. ``` import std; void main() { writeln(add(3, 4)); } nogc int add(int x, int y) { return x+y; } ``` The use cases of nogc and BetterC are very different. With BetterC you lose classes, dynamic arrays, and associative arrays, among other things.
Sep 07
On Sunday, 8 September 2024 at 00:18:53 UTC, Kapendev wrote:On Sunday, 8 September 2024 at 00:10:05 UTC, Kapendev wrote:And test every function you call, and every function that function calls, and so on. And hope that nobody changes the implementation after you've checked it, etc..On Saturday, 7 September 2024 at 13:06:45 UTC, Lance Bachmeier wrote:And if you are unsure if a function allocates with the gc, you can always test.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.
Sep 08
On Sunday, 8 September 2024 at 09:14:21 UTC, claptrap wrote:On Sunday, 8 September 2024 at 00:18:53 UTC, Kapendev wrote:IFF d had a full time embedded and wasm std dev, and a backlog of bug reports shorter then 10 years long, it would be fine as they make whatever style guide changes and edge cases could be solved as they came up from real use. Adding nogc to an existing old tech debt project is less realistic then doing an separate new std; and that new std could just be compiled with bettercOn Sunday, 8 September 2024 at 00:10:05 UTC, Kapendev wrote:And test every function you call, and every function that function calls, and so on. And hope that nobody changes the implementation after you've checked it, etc..On Saturday, 7 September 2024 at 13:06:45 UTC, Lance Bachmeier wrote:And if you are unsure if a function allocates with the gc, you can always test.On Saturday, 7 September 2024 at 08:05:10 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.
Sep 08
On Sunday, 8 September 2024 at 00:10:05 UTC, Kapendev wrote:You just don't use ` nogc`. My point is that your code is already nogc. No need for an attribute.Same can be said for every other attribute, let's get rid of all of them! No of course not. We use attribute not because we can't write that code without them, but because we want the compiler to check if something doesn't unexpectedly find its way in. With changing requirements and changing authors, it is easy for almost all of your assumptions and conventions to break. Having an attribute is so much better than having to write a comment and/or needing to be extra vigilant at code review time.
Sep 07
On Friday, 6 September 2024 at 09:37:48 UTC, solidstate1991 wrote:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC. [...]Please, just a big no. /P
Sep 07
Some introspection: ` nogc` has an unintended effect of forcing its users to do optimization in the form of using preallocated memory. Might be replicated by using IDE extensions, which could warn the user for `malloc()` and similar calls.
Sep 07
solidstate1991 kirjoitti 6.9.2024 klo 12.37:A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC. [snip]Putting my thoughts without having looked at other replies first. No idea whether I'll go along with or against with what most have written. Of these two, my gut reaction it's betterC that should (mostly) go. It is far better for the language to be pay-as-you-go. If not using non-shared static variables and not starting threads, the langauge shouldn't (attempt to) link in threading from the runtime. If not using exceptions, exception throwing/catching shouldn't be linked in. And so on. For the most part, simply not using the D-specific functionality would be equal to betterC in this scheme. There are some exceptions to this rule. For example, assertions normally throw an error on failure instead of just aborting, and a header-only vanilla D library probably needs to provide module constructors and destructors even if they do nothing to avoid ABI changes if such logic is added in the future. But even those can be solved with individual compiler switches. I think betterC should ideally be only be a shortcut for some set of compiler switches that that could all be enabled individually just as well, as opposed to a monolithic set of compiler and language changes. As for ` nogc`, I do agree it's benefit-to-weight ratio feels questionable. If we didn't have it, I would be sceptical about adding it to the language. But since it has already been in the language for a long time, it needs stronger justification for removal than rejecting it anew would need, even with editions. Plus, people do occasionally find it useful. Therefore I'm a bit sceptical about but not strongly against removing it.
Sep 09
On Monday, 9 September 2024 at 16:00:47 UTC, Dukc wrote:solidstate1991 kirjoitti 6.9.2024 klo 12.37:as far as I know theres only 3 ways to care about betterc; and none of which get meaningful support; restructuring it to be "pay as you go" will probably not find, much less implement, these theatrical alt better compiler switches.A lot of people are arguing (especially on Discord) that ` nogc` should be discarded entirely in favor of betterC. [snip]Putting my thoughts without having looked at other replies first. No idea whether I'll go along with or against with what most have written. Of these two, my gut reaction it's betterC that should (mostly) go. It is far better for the language to be pay-as-you-go. If not using non-shared static variables and not starting threads, the langauge shouldn't (attempt to) link in threading from the runtime. If not using exceptions, exception throwing/catching shouldn't be linked in. And so on. For the most part, simply not using the D-specific functionality would be equal to betterC in this scheme. There are some exceptions to this rule. For example, assertions normally throw an error on failure instead of just aborting, and a header-only vanilla D library probably needs to provide module constructors and destructors even if they do nothing to avoid ABI changes if such logic is added in the future. But even those can be solved with individual compiler switches. I think betterC should ideally be only be a shortcut for some set of compiler switches that that could all be enabled individually just as well, as opposed to a monolithic set of compiler and language changes. As for ` nogc`, I do agree it's benefit-to-weight ratio feels questionable. If we didn't have it, I would be sceptical about adding it to the language. But since it has already been in the language for a long time, it needs stronger justification for removal than rejecting it anew would need, even with editions. Plus, people do occasionally find it useful. Therefore I'm a bit sceptical about but not strongly against removing it.
Sep 09
gc is a "stop the world" gc, but it can be managed in a real-time environment: 1. Collections are only run when a call to allocate memory from the gc is made. The gc does not randomly run, and will not run if the code is not calling the gc. 2. Collections can be disabled and enabled. 3. Real time programs have startup and shutdown, where GC can be used, because the real time part is not running then. 4. Pre-allocate memory for the real time part, so it will not need to allocate memory. 5. malloc/free can consume arbitrarily large amounts of time. 6. put the real time code in a thread that is not paused by the GC collection cycle (this also means that thread cannot call the GC, and cannot be the "owner" of the GC allocations it uses). 7. Minimize the time spent in real-time code by collecting the asynchronous events and posting them to a queue that the non-real-time code can execute.
Sep 09