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

separate object_t::key_type from basic_json::key_type, and use an allocator which returns object_t::key_type #1274

Closed
timprepscius opened this issue Oct 3, 2018 · 3 comments
Labels
state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@timprepscius
Copy link

  • What

I would like the key_type which is searched for:
json j = { "hi", "there" };
j.at("hi") <--- that "hi" is a going to be object_t::key_type, I believe.

To be different from the internal key type
for instance object_t::key_type might be string_view,
but the parameter types, might still be string... but most likely would be string_view (if the internal type is string_view).

  • Why?

I deal with json which has many millions of objects containing the same keys.
I would like there to be an allocator type which allocates strings in a big set of strings. And returns the string_view of that string, rather than a new string, (or a may even return a const char * of the string.c_str())

This is close to the way the jvm allocates strings.

In this way, I would save a lot of memory, and also, key/value lookups in maps would be faster.

@timprepscius
Copy link
Author

I made a patch which separates the internal map key type from the external map key type. This allows for string_view to be used. Which, in my case, collapses memory allocation considerably. This is just a simple rough cut, will need to be redone later.

I purposefully did not do all the templatization, because I figure the owner of this repository would have clear ideas about how that should be done.

make_string_view_as_map_key_possible.diff.txt

@nlohmann
Copy link
Owner

Thanks! A PR would still be very welcomed!

@stale
Copy link

stale bot commented Nov 25, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Nov 25, 2018
@stale stale bot closed this as completed Dec 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

2 participants