Performance Help
I am using dsl-json to serialize a list of object into string and write it to an outputstream. The following is my code
private static final DslJson.SimpleStringCache SIMPLE_STRING_CACHE = new DslJson.SimpleStringCache(); private static final Settings<List<NodeWithChildrenDTO>> DSL_SETTINGS = new Settings<List<NodeWithChildrenDTO>>().includeServiceLoader().skipDefaultValues(true). useKeyCache(SIMPLE_STRING_CACHE).useStringValuesCache(SIMPLE_STRING_CACHE); private static final DslJson<List<NodeWithChildrenDTO>> DSL_JSON = new DslJson<>(DSL_SETTINGS); private static final _NodeWithChildrenDTO_DslJsonConverter.ObjectFormatConverter k = new _NodeWithChildrenDTO_DslJsonConverter.ObjectFormatConverter(DSL_JSON);
And the convert code is as follows
final JsonWriter jsonWriter = DSL_JSON.newWriter(); jsonWriter.serialize(nodeWithChildrenDTOS, k); jsonWriter.toStream(entityStream); jsonWriter.reset(); entityStream.close()
I feel I am not getting good performance and feel am doing things incorrectly. Any suggestions is highly appreciated
Couple of things...
String cache will help with reading of strings, but mostly only with memory pressure. It will actually have lower performance than allocating strings all the time. But this is for reading, not writing. You should not be allocating newWriter in the method. Instead you should reuse it. Either with something like thread local or within your reusable context. Depending on how big your string is it might be faster to write directly to output stream instead of first writer than flushing to stream. Since you are allocating and then increasing it until it can contain all your output thats probable the main source of your "problems".
I can't really tell what your model is, but thats the most important aspect to all of this since performance is mostly bound by performance of specific type codecs.