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

Make the Short JsonValue optional (and ideally just make JsonValue::String use a string pool for small sizes?) #10

Open
navi-desu opened this issue Sep 30, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@navi-desu
Copy link

i was using the json crate to write a json-ld processor, and hit the problem of it spilling JsonValue::Sort(_) on, well, short strings.

not only is this a pain, because now everywhere that i would handle strings i now need to handle sorts as well (and uses of if let JsonValue::String(str) = json.get(key) now would need to have all the code duplicated to handle else if let JsonValue::Short = json.get(key) as well (or one would need to normalize both to a variable but at that point if it's a short you're allocating to be able to handle it in a streamlined way)

and since Short is a stack array, of 30 chars, it could be a problem if too many where made, as the lib doesn't track stack size, could lead to a stack overflow.

ideally, instead of a different type, JsonValue::String could just get it's memory from a string pool instead, if it's a short string. this would simplify handling of the data, and avoid the possible stack overflow problem.

proposed solution: initially just add a feature flag that disables parsing into shorts all together (temporarily), then adapt JsonValue::String to use a string pool on short string and a normal allocated String on long string


initially i would open this issue on the json-rs github, but it seems dead, while this fork seems alive

@gierens
Copy link
Member

gierens commented Oct 25, 2023

Hi @navi-desu, sorry for the late reply, been a little busy the last few weeks.

I just looked at the relevant code and this sounds like an interesting proposal. As a breaking change a feature flag definitively makes sense. Would you like to work on this, or is this a request for us?

@gierens gierens added the enhancement New feature or request label Oct 25, 2023
@navi-desu
Copy link
Author

Would you like to work on this, or is this a request for us?

i was either considering using serde_json or writing my own json parser, after getting annoyed at json (the old version of this) for two things, this, and not being able to iterate over JsonObject moving the values (which i just noticed is fixed here, yay!).

if no one else is interested, i could try to implement this change for String.

@gierens
Copy link
Member

gierens commented Oct 26, 2023

I'm currently a little short on time so I don't know how quick I could try to work on this. If you want to give it a try that would be great and much appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants