Comments (3)
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:
- You can try skipping over the names, since fillName will calculate hash of the value, but since you don't use it, you can just call reader.skip() instead.
- You can try and reusing string values from the cache instead of allocating new string all the time. Not sure if that will help, but its something to try. You can do that by initializing library with: https://github.com/ngs-doo/dsl-json/blob/master/library/src/main/java/com/dslplatform/json/DslJson.java#L229
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] ]
from dsl-json.
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 examples/
?
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.
from dsl-json.
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
which you can use to fill the object instance with values without allocating that object instance.
There is no example on how to use it here (outside of tests) :(
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.
from dsl-json.
Related Issues (20)
- Support kotlin inline classes HOT 17
- Java annotations over @JsonAttribute cause compile-time error. (Only with Java records) HOT 3
- which are the java versions supported? HOT 2
- About json field policy of object HOT 2
- Can't generate dsl for some kotlin data classes HOT 1
- Dependency org.postgresql:postgresql, leading to CVE problem HOT 1
- Question: Testing File Read with dsl-json HOT 2
- serialize/deserialize Set as a List HOT 2
- Question - Is possible to use array format with discriminator in abstract classes HOT 2
- Stack overflow error caused by dsl-json serialization Map HOT 2
- Does DSL-JSON Scale? HOT 5
- Polimorphic adapters HOT 9
- @CompiledJson annotation does not bind byte[] to BinaryConverter in v2.0.0 HOT 2
- Failure to serialize the basic generic objects. HOT 4
- support for kotlin value classes HOT 5
- JsonValue syntax tree HOT 7
- Filed filtering? HOT 4
- Re-using reader/writer. Make reset method public HOT 3
- Support reader.next(Class) inside a converter HOT 3
- Is there any support for deserialiazing from already parsed data? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dsl-json.