avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Busbey (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (AVRO-1640) Does SpecificData.schemaCache actually do anything?
Date Fri, 18 Aug 2017 13:17:01 GMT

     [ https://issues.apache.org/jira/browse/AVRO-1640?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sean Busbey updated AVRO-1640:
------------------------------
    Labels: should_be_dev_discussion  (was: )

> Does SpecificData.schemaCache actually do anything?
> ---------------------------------------------------
>
>                 Key: AVRO-1640
>                 URL: https://issues.apache.org/jira/browse/AVRO-1640
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>    Affects Versions: 1.7.7
>            Reporter: Silas Davis
>            Priority: Minor
>              Labels: should_be_dev_discussion
>
> I've been looking at the source code for SpecificData. On line 182 a schemaCache is defined
as a WeakHashMap.
> Having looked into how WeakHashMap works - it stores a WeakReference for the keys of
the map but not the values, I can't see how the schemaCache actually provides a cache. I think
it just stores all Schema objects it has ever seen, and never expires any. This is because
it stores keys of type java.lang.reflect.Type key, typlically a Class<?>, which typically
never fall out of reference. The only way the Class (a static singleton object) will be garbage
collected is if the ClassLoader that holds a reference to it is garbage collected. This mostly
doesn't happen, so the schemaCache is really just behaving as a HashMap.
> It seems like WeakHashMap is commonly mistakenly used as a cache:
> - http://stackoverflow.com/questions/1802809/javas-weakhashmap-and-caching-why-is-it-referencing-the-keys-not-the-values
> - http://www.codeinstructions.com/2008/09/weakhashmap-is-not-cache-understanding.html
> Perhaps I am missing something, like Avro's use of ClassLoaders meaning that Class objects
do get collected, apologies if so.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message