Re: refcounting [WAS: More Rust code]

2017-08-02 Thread Joshua Cranmer 

On 8/2/2017 6:37 AM, Enrico Weigelt, metux IT consult wrote:

On 31.07.2017 13:53, smaug wrote:




Reference counting is needed always if both JS and C++ can have a
pointer to the object.


By the way - just curious:

Anybody already thought about garbage collection ?


Yes. About a decade ago, Mozilla invested some resources in being able 
to automatically rewrite the codebase to use GC instead of reference 
counting: .


Some conclusions:
1. Automated rewriting of C++ code is possible (this is when the only 
significant open-source C++ compiler relied on horribly inaccurate 
position tracking, so it actually was a big deal).
2. Converting from reference-counting to conservative GC is barely 
possible. (I recall bsmedberg saying that the resulting build could go 
for a few minutes before crashing)
3. It's not the performance win you think it is. The main performance 
wins are a compacting GC, which minimizes memory use over time and makes 
heap allocation basically a pointer bump. On the other hand, now you 
have to have threadsafe reference counting on every object.



That wouldn't have the problem w/ circular graphs, and should make the
whole code smaller and faster.


See the results on the linked page. It was neither smaller, nor faster.

We already have a cycle-collector, which is basically an opt-in garbage 
collector (it only looks at a subset of the total ownership graph). The 
main difficulty in using it is having to annotate classes in cycles, but 
this is exactly the sort of thing that's easy to write in a #[derive()] 
attr in Rust.


--
Joshua Cranmer
Thunderbird and DXR developer
Source code archæologist

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: refcounting [WAS: More Rust code]

2017-08-02 Thread Ted Mielczarek
On Wed, Aug 2, 2017, at 08:32 AM, Nathan Froyd wrote:
> On Wed, Aug 2, 2017 at 7:37 AM, Enrico Weigelt, metux IT consult
>  wrote:
> > On 31.07.2017 13:53, smaug wrote:
> >> Reference counting is needed always if both JS and C++ can have a
> >> pointer to the object.
> >
> > Anybody already thought about garbage collection ?
> 
> Reference counting is a garbage collection technique.  See
> https://en.wikipedia.org/wiki/Reference_counting where the
> introductory paragraphs and the first section specifically refer to it
> as a garbage collection technique.  Or consult _The Garbage Collection
> Handbook_ by Jones, Hosking, and Moss, which has an entire chapter
> devoted to reference counting.
> 
> Note also that Gecko's reference counting tends to be cheaper than the
> reference counting assumed in the literature, since many of Gecko's
> reference-counted objects can use non-thread-safe reference counting,
> as said objects are only ever accessed on a single thread.  (Compare
> http://robert.ocallahan.org/2012/06/computer-science-in-beijing.html)
> 
> Changing the garbage collection technique used by our C++ code to
> something other than reference counting would be a large project of
> dubious worth.

Also we tried that once and it didn't work well for various reasons:
https://wiki.mozilla.org/XPCOMGC

-Ted
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


Re: refcounting [WAS: More Rust code]

2017-08-02 Thread Nathan Froyd
On Wed, Aug 2, 2017 at 7:37 AM, Enrico Weigelt, metux IT consult
 wrote:
> On 31.07.2017 13:53, smaug wrote:
>> Reference counting is needed always if both JS and C++ can have a
>> pointer to the object.
>
> Anybody already thought about garbage collection ?

Reference counting is a garbage collection technique.  See
https://en.wikipedia.org/wiki/Reference_counting where the
introductory paragraphs and the first section specifically refer to it
as a garbage collection technique.  Or consult _The Garbage Collection
Handbook_ by Jones, Hosking, and Moss, which has an entire chapter
devoted to reference counting.

Note also that Gecko's reference counting tends to be cheaper than the
reference counting assumed in the literature, since many of Gecko's
reference-counted objects can use non-thread-safe reference counting,
as said objects are only ever accessed on a single thread.  (Compare
http://robert.ocallahan.org/2012/06/computer-science-in-beijing.html)

Changing the garbage collection technique used by our C++ code to
something other than reference counting would be a large project of
dubious worth.

-Nathan
___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform


refcounting [WAS: More Rust code]

2017-08-02 Thread Enrico Weigelt, metux IT consult

On 31.07.2017 13:53, smaug wrote:




Reference counting is needed always if both JS and C++ can have a
pointer to the object.


By the way - just curious:

Anybody already thought about garbage collection ?

That wouldn't have the problem w/ circular graphs, and should make the
whole code smaller and faster.


--mtx

___
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform