Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed the '_lines' data structure from Appender to built-in array, as the former leaks memory #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbecerescu
Copy link
Contributor

@cbecerescu cbecerescu commented Dec 9, 2019

For example, when translating kernel header files, memory usage for d++ reached 6-7GB on an 8GB machine (and we no longer could spawn a process for CPP to preprocess the .tmp file).

After seeing this issue, I changed from Appender to built-in array type and got a max RAM usage of 2GB (and CPP ran successfully).

Regarding performance, Edi ran some tests and saw no major difference between the Appender and the built-in array (test done on 1 million 20 char-long strings being appended, Appender being faster by 20ms).

@edi33416
Copy link

edi33416 commented Dec 9, 2019

The pseudo-benchmark code that I wrote

import std.array;                                                                                                                                                                                                                                                                         
import std.random;

void main()
{
    //Appender!(string[]) arr;
    string[] arr;

    int n = 1_000_000;

    for (int i = 0; i < n; ++i)
    {   
        string s;
        for (int j = 0; j < 20; ++j)
        {
            char c = cast(char) rndGen.front;
            rndGen.popFront();
            s ~= c;
        }

        arr ~= s;
    }   
}

I felt that using random and rndGen to generate the random strings is nice as that also requires some processing so we also "simultate" some work.

@atilaneves
Copy link
Owner

The performance considerations need to be measured with real-world usage in dpp, not in an external micro benchmark. The reason it's an appender in the first place is because of how long it was taking to process Python.h. I suggest measuring how it affects performance by running dpp on a single-line dpp file with #include "Python.h".

@Laeeth
Copy link

Laeeth commented Dec 11, 2019

We perhaps should fix Appender !

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.

4 participants