Java Reference
In-Depth Information
Table 10-13. Network transfer time for 10,000 objects
Same machine Broadband WAN
No compression
30.1 seconds
150.1 seconds
Compression/decompression 41.3 seconds
54.3 seconds
Compression only
28.0 seconds
44.1 seconds
The fastest possible network communication is between two processes on the same ma-
chine—that communication doesn't go onto the network at all, though it does send data
through the operating system interfaces. Even in that case, compressing the data and lazily
decompressing it has resulted in the fastest performance (at least for this test—a smaller data
amount may still show a regression). And the order of magnitude difference in the amount of
data has made a (predictably) large difference in the total time once a slower network is in-
Keeping Track of Duplicate Objects
This section began with an example of how not to serialize data that contains object referen-
ces, lest the object references be compromised when the data is deserialized. However, one
of the more powerful optimizations possible in the writeObject() method is to not write
out duplicate object references. In the case of the StockPriceHistoryImpl class, that means
not writing out the duplicate references of the prices map. Because the example uses a
standard JDK class for that map, we don't have to worry about that: the JDK classes are
already written to optimally serialize their data. Still, it is instructive to look into how those
classes perform their optimizations in order to understand what is possible.
In the StockPriceHistoryImpl class, the key structure is a TreeMap . A simplified version
of that map appears in Figure 10-2 . With default serialization, the JVM would write out the
primitive data fields for node A; then it would recursively call the writeObject() method
for node B (and then for node C). The code for node B would write out its primitive data
fields, and then recursively write out the data for its parent field.
But wait a minute—that parent field is node A, which has already been written. The object
serialization code is smart enough to realize that: it doesn't rewrite the data for node A. In-
stead, it simply adds an object reference to the previously written data.
Search WWH ::

Custom Search