-
Notifications
You must be signed in to change notification settings - Fork 106
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
Deserializing in real time, mutable objects #54
Comments
Ideally you shouldn't try to write manual parsing with DSL-JSON (except for some custom types) since there should be no overhead with using high level API consuming compile time bindings. But your code looks fine. There are two minor things you could improve:
Also, since you are not really using compile time bindings, you don't need that withRuntime or includeServiceLoader (at least not for this example). It doesn't affect your code, so you don't need to remove it though. And if you have control over the JSON message, you can change the format no to be { "id": "foo", "price": num } but rather into ["foo", num] or as a list [ ["foo1",num1], ["foo2",num2] ] |
Regarding compile time bindings I thought this method would result in the least overhead possible. I'm curious now how you achieved no overhead with bindings. Any particular example I should check in I'm parsing it manually because I have multiple versions of the same parser, depending on what API I'm consuming, so this way the parser is isolated and stored in each FooApiInterface. Maybe I should check the other way of doing this and refactor the code if it turns out to have the same performance but is simpler... Regarding StringCache I have implemented a StringCache for this purpose, it is pretty similar to your SimpleStringCache except it handles hash collisions nicely, all with zero allocation. Check CollisionlessStringCache. DslJson.Settings<Object> settings = new DslJson.Settings<>()
.useStringValuesCache(new StringCache(512));
DslJson<Object> dslJson = new DslJson<>(settings);
JsonReader reader = dslJson.newReader();
// ... UPDATE: In a quick test I've seen no increase in performance with either SimpleStringCache or my CollisionlessStringCache, I'm guessing creating new strings always is faster than the overhead added by those classes, specially if the strings are short (4-6 chars long) like in my case. |
There is a bind interface for mutable objects: https://github.com/ngs-doo/dsl-json/blob/master/library/src/main/java/com/dslplatform/json/JsonReader.java#L1110 I would consider any scenario in which writing code by hand yields significantly better results an issue to fix. Usually there is no real reason why similar code cant be created by the annotation processor. |
I'm deserializing an array of objects as follows:
It's working fine, but I'm not sure this is the fastest way of doing this as I barely know DSL-JSON api.
How can I increase the performance?
The text was updated successfully, but these errors were encountered: