[Rd] object.size vs lobstr::obj_size

Tomas Kalibera tom@@@k@||ber@ @end|ng |rom gm@||@com
Fri Mar 27 17:07:47 CET 2020

On 3/27/20 4:39 PM, Hervé Pagès wrote:
> Hi Tomas,
> On 3/27/20 07:01, Tomas Kalibera wrote:
>> they provide an over-approximation
> They can also provide an "under-approximation" (to say the least) e.g. 
> on reference objects where the entire substance of the object is 
> ignored which makes object.size() completely meaningless in that case:
>   setRefClass("A", fields=c(stuff="ANY"))
>   object.size(new("A", stuff=raw(0)))      # 680 bytes
>   object.size(new("A", stuff=runif(1e8)))  # 680 bytes
> Why wouldn't object.size() look at the content of environments?

Yes, the treatment of environments is not "over-approximative". It has 
to be bounded somewhere, you can't traverse all captured environments, 
getting to say package namespaces, global environment, code of all 
functions, that would be too over-approximating. For environments used 
as hash maps that contain data, such as in reference classes, it would 
of course be much better to include them, but you can't differentiate 
programmatically. In principle the same environment can be used for both 
things, say a namespace environment can contain data (not clearly 
related to any user-level R object) as well as code. Not mentioning 
things like source references and parse data.


> Thanks,
> H.

More information about the R-devel mailing list