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

json::serialize takes an extraordinary amount of time on clang / libc++ #697

Closed
madmongo1 opened this issue Apr 23, 2022 · 8 comments
Closed

Comments

@madmongo1
Copy link
Collaborator

PLEASE DON'T FORGET TO "STAR" THIS REPOSITORY :)

When reporting a bug please include the following:

Version of Boost

1.79

Steps necessary to reproduce the problem

Compile the linked program https://github.com/madmongo1/json-bug-1

with:
clang 13
-stdlib=libc++

All relevant compiler information

clang 13
-stdlib=libc++

Run the executable in the same directory as the bundled log file demo.log.

The program reads one line of text from the file, parses it to json and then serialises the json value back to a string.

With GCC, the serialisation is instantaneous.

With clang (in both debug and release configurations), the parsing is instantaneous, but the serialisation takes many minutes.

It does make progress, but incredibly slowly. I have waited 5-10 minutes. In that time, the program was only able serialise approx 140k of text.

@sehe
Copy link
Contributor

sehe commented Apr 23, 2022

The problem is clearly linked to libc++, because I cannot reproduce it unless I add -stdlib=libc++ (which isn't default on my system).

@vinniefalco
Copy link
Member

What is the std::string growth policy of libc++ compared to clang?

See:

@madmongo1
Copy link
Collaborator Author

I use -stdlib=libc++ with clang as it's seemingly the only way to get coroutine support.

@sehe
Copy link
Contributor

sehe commented Apr 23, 2022

Whatever it is, it's taking 96% of execution (even if I reserve the output string to 4'472'628 in serialize.ipp, so it's intermediate strings?).
image

@vinniefalco
Copy link
Member

libc++ reserve( capacity() + 1 ) grows capacity 16 bytes at a time

@sehe
Copy link
Contributor

sehe commented Apr 23, 2022

parsing
...serialising
...serialised: 4472628 chars

real    0m0,079s
user    0m0,059s
sys     0m0,020s

@sehe
Copy link
Contributor

sehe commented Apr 23, 2022

And no leaks reported (valgrind)

==9036== All heap blocks were freed -- no leaks are possible

@grisumbras
Copy link
Member

Fixed in 5ca4fb3

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

No branches or pull requests

4 participants