johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Dev <>
Subject JsonValue immutability
Date Tue, 15 Jul 2014 11:39:59 GMT
To open another discussion ;-) i looked on the JsonValue
implementations regarding immutability (as the API requires).

Looks like that doing real immutability have a really bad performance
impact (at least in my prototype implementation which is here
So i understand why the initial implementation deals with the
JsonArrayImpl.addInternal() and JsonObjectImpl.putInternal(). But if i
were a nitpicker i would say thats not immutable :-)
The main performance impact is due to the builder implementations i
think if the values are really immutable.

But at least the JsonValue implementations itself can be immutable
without big perf drawbacks hopefully. To make them "more" immutable
(and keep the put/addInternal()) i suggest:

For JsonArrayImpl
- getValuesAs() should return unmodifiable list

- subList(int fromIndex, int toIndex) should return unmodifiable list

- listIterator(int index) disallow to change list

- make class final

- make hashcode caching threadsafe (int terms of "volatile")

- make addInternal package private

For JasonObjectImpl
- keySet() should return unmodifiable set

- values()  should return unmodifiable collection

- entrySet() should return unmodifiable set (tricky ->

- make class final

- make hashcode caching threadsafe (int terms of "volatile")

- make putInternal package private

For the other JsonValue implementations
- make classes final
- make hashcode caching threadsafe (int terms of "volatile")

Your opinion?


Hendrik Saly (salyh, hendrikdev22)
PGP: 0x22D7F6EC

View raw message