Skip to content

builtin, v: support -gc boehm on systems with libgc-dev installed#9382

Merged
medvednikov merged 12 commits intovlang:masterfrom
spytheman:experimental_libgc
Mar 20, 2021
Merged

builtin, v: support -gc boehm on systems with libgc-dev installed#9382
medvednikov merged 12 commits intovlang:masterfrom
spytheman:experimental_libgc

Conversation

@spytheman
Copy link
Copy Markdown
Contributor

@spytheman spytheman commented Mar 20, 2021

This PR implements replacing malloc/calloc/realloc/free with GC_MALLOC/GC_MALLOC/GC_REALLOC/GC_FREE, when you pass -gc boehm during compilation, i.e. linking and using the Boehm-Demers-Weiser conservative C/C++ Garbage Collector from https://github.com/ivmai/bdwgc, which is often packaged and available on Linux distributions.

The intent is reducing the memory usage of programs, that process large amounts of text in batch mode on low memory environments (small VPSes), and for which a few ms of garbage collection pauses from time to time do not matter much.

NB1: this new option does not affect -autofree, it is independent from it, and can be used with or without -autofree (although I have not tested it with -autofree for now).

NB2: V still can not compile itself with -gc boehm, I am not sure yet why.
(edit: also vlib/builtin/map_test.v fails which may be related 🤔 )

image

fn main() {
        mut a := 'abc'.repeat(1000)
        for i in 0 .. 100000 {
        b := '$a|$a|$a|$a'
                a = a.replace('c', 'd')
                a = a.replace('d', 'x')
                a = a.replace('x', 'y')
                a = a.replace('y', 'z')
                a = a.replace('z', 'W')
                a = a.replace('z', 'c')
                if i % 10000 == 0 {
                        println('i: ${i:10} ${a[0..10]} ${b[30..60]}')
                }
        }
}

image

@spytheman spytheman marked this pull request as draft March 20, 2021 00:47
@spytheman spytheman force-pushed the experimental_libgc branch from 178ff2e to adbf466 Compare March 20, 2021 06:34
@spytheman spytheman force-pushed the experimental_libgc branch from b49f4fb to 302b849 Compare March 20, 2021 09:59
@spytheman spytheman changed the title builtin, v: support -d libgc on systems with libgc installed builtin, v: support -gc boehm on systems with libgc-dev installed Mar 20, 2021
@spytheman spytheman marked this pull request as ready for review March 20, 2021 13:13
@medvednikov medvednikov merged commit 8810af7 into vlang:master Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants