Thread overview
dub and -lowmem: does nothing
Mar 20, 2020
Anonymouse
Mar 21, 2020
kinke
Mar 21, 2020
Anonymouse
March 20, 2020
Manjaro/Arch x86_64, dmd v2.091.0, dub 1.19.0.

I have a project which dmd on Windows fails to compile, throwing an OutOfMemoryError[1]. Up until recently it could be worked around by using `--build-mode=singleFile`, but now that's no longer enough and errors out too (on AppVeyor).

The obvious solution is to set `-lowmem` in dub.sdl, but it seems to do nothing, as measured *in Linux* by the amount of memory used with zsh's `time` shell built-in.

If using zsh time, you may need the following environmental variable to get the required output:

```
TIMEFMT='%J   %U  user %S system %P cpu %*E total
avg shared (code):         %X KB
avg unshared (data/stack): %D KB
total (sum):               %K KB
max memory:                %M MB
page faults from disk:     %F
other page faults:         %R'
```

A gutted test branch: (has two dependencies)
> git clone https://github.com/zorael/tests.git -b lowmem

1. `dub build` on a default configuration without -lowmem defined shows some ~2011 Mb used.
2. If I run dub with -v, then copy the dmd command it runs and execute it manually, I get the same ~2012 Mb used. Close enough, makes sense.
3. `dub build -c lowmem` for an identical configuration but with dflags "-lowmem" added, nothing changes and I still get ~2011 Mb used.
4. If I run dub with -v on the lowmem configuration and copy/paste *the same command it ran*, unmodified, I suddenly get the more expected ~1183 Mb used.

Log: https://pastebin.com/raw/yDnCj1KJ

-lowmem is visibly present in the dmd command listed with -v, but it seems to do nothing through dub.

How? Why?


> dub remove lu --version="*"
> dub remove dialect --version="*"

[1]: https://issues.dlang.org/show_bug.cgi?id=20562
March 21, 2020
On Friday, 20 March 2020 at 23:37:52 UTC, Anonymouse wrote:
> 4. If I run dub with -v on the lowmem configuration and copy/paste *the same command it ran*, unmodified, I suddenly get the more expected ~1183 Mb used.
>
> [...]
>
> -lowmem is visibly present in the dmd command listed with -v, but it seems to do nothing through dub.
>
> How? Why?

Most likely because dub doesn't actually invoke the listed command, but uses a response file to work around cmdline length limits. -lowmem in response files is ignored by DMD (needs to be parsed and set before druntime initialization, but response file parsing needs druntime + GC). It works for LDC though.
March 21, 2020
On Saturday, 21 March 2020 at 00:17:37 UTC, kinke wrote:
> Most likely because dub doesn't actually invoke the listed command, but uses a response file to work around cmdline length limits. -lowmem in response files is ignored by DMD (needs to be parsed and set before druntime initialization, but response file parsing needs druntime + GC). It works for LDC though.

So there is no way to do -lowmem with dub and dmd?

I'm not having out-of-memory problems with ldc, luckily.
March 21, 2020
On 3/21/20 5:34 AM, Anonymouse wrote:
> On Saturday, 21 March 2020 at 00:17:37 UTC, kinke wrote:
>> Most likely because dub doesn't actually invoke the listed command, but uses a response file to work around cmdline length limits. -lowmem in response files is ignored by DMD (needs to be parsed and set before druntime initialization, but response file parsing needs druntime + GC). It works for LDC though.
> 
> So there is no way to do -lowmem with dub and dmd?
> 
> I'm not having out-of-memory problems with ldc, luckily.

I found the same thing. dub says it's passing -lowmem (and at the same time I wanted it to print GC profile data). Does not work.

I've done exactly what you did, use -v and then copy-paste the final command line.

Very annoying. If there's not a bug on this yet, I'd say there needs to be (on DMD I would say).

-Steve