[ 
https://issues.apache.org/jira/browse/THRIFT-594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12760865#action_12760865
 ] 

Esteve Fernandez commented on THRIFT-594:
-----------------------------------------

I think this can be implemented in a more general way by adding a static method 
(e.g. create) that would take an instance of a subclass of TProtocol to 
generated structs, and which would have an optional argument for a custom 
allocator.

The default allocator would return a new instance of the structure, but one 
could write another one that maintains a cache of already generated structs. It 
could also be ported to other languages, for example, if you're using C++ and 
Threading Building Blocks, you may want to use any of its allocators. This 
approach is similar to what I did in THRIFT-301, except that I didn't add 
support for custom allocators, though.

> Add "intern" method to generated structs
> ----------------------------------------
>
>                 Key: THRIFT-594
>                 URL: https://issues.apache.org/jira/browse/THRIFT-594
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Compiler (Java), Library (Java)
>    Affects Versions: 0.2
>            Reporter: Bryan Duxbury
>            Priority: Minor
>             Fix For: 0.2
>
>
> Thrift structs can take up a lot of memory in Java. In my particular 
> application, many of the structs I load have common subcomponents. When 
> deserializing these structs today, each copy of the common subcomponents 
> takes up a fresh chunk of memory. 
> To reduce this memory usage, I propose that we add an "intern" method to 
> Thrift structs. This method would maintain a static class-level cache of 
> canonical versions of instances of objects. When calling "intern", if the 
> object was not in the cache, it would add it and return the same struct. If 
> it was in the cache, it would return the canonical version, allowing the 
> non-canonical version to be dropped during garbage collection.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to