Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8009)

Issue 12708048: Avoid Scheme-computed Skyline_pair values to get collected before use (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
10 years, 8 months ago by dak
Modified:
10 years, 6 months ago
Reviewers:
Keith
CC:
lilypond-devel_gnu.org
Visibility:
Public.

Description

Avoid Scheme-computed Skyline_pair values to get collected before use Retaining them as SCM values until they are no longer needed avoids premature garbage collection. This addresses circumstances in connection with issue 3490. Uploaded independently from the copy constructor patch since that patch might hide the symptoms.

Patch Set 1 #

Total comments: 4
Unified diffs Side-by-side diffs Delta from patch set Stats (+16 lines, -18 lines) Patch
M lily/side-position-interface.cc View 4 chunks +16 lines, -18 lines 4 comments Download

Messages

Total messages: 6
Keith
looks quite good to me, of course. https://codereview.appspot.com/12708048/diff/1/lily/side-position-interface.cc File lily/side-position-interface.cc (left): https://codereview.appspot.com/12708048/diff/1/lily/side-position-interface.cc#oldcode216 lily/side-position-interface.cc:216: Skyline my_dim; ...
10 years, 8 months ago (2013-08-11 19:30:46 UTC) #1
dak
https://codereview.appspot.com/12708048/diff/1/lily/side-position-interface.cc File lily/side-position-interface.cc (left): https://codereview.appspot.com/12708048/diff/1/lily/side-position-interface.cc#oldcode216 lily/side-position-interface.cc:216: Skyline my_dim; On 2013/08/11 19:30:46, Keith wrote: > I ...
10 years, 8 months ago (2013-08-11 19:46:04 UTC) #2
Keith
On Sun, 11 Aug 2013 12:46:04 -0700, <dak@gnu.org> wrote: > https://codereview.appspot.com/12708048/diff/1/lily/side-position-interface.cc > File lily/side-position-interface.cc (left): ...
10 years, 8 months ago (2013-08-11 20:41:48 UTC) #3
dak
On 2013/08/11 20:41:48, Keith wrote: > On Sun, 11 Aug 2013 12:46:04 -0700, <mailto:dak@gnu.org> wrote: ...
10 years, 8 months ago (2013-08-11 21:07:03 UTC) #4
Keith
On 2013/08/11 21:07:03, dak wrote: > It's conceivable that this change helped, > though there ...
10 years, 8 months ago (2013-08-12 05:50:10 UTC) #5
dak
10 years, 8 months ago (2013-08-12 07:13:44 UTC) #6
On 2013/08/12 05:50:10, Keith wrote:
> On 2013/08/11 21:07:03, dak wrote:
> 
> > It's conceivable that this change helped,
> > though there don't seem to be a lot of opportunities
> > for garbage collection between return of the SCM
> > value and use of the Skyline_pair.
> 
> There is ample opportunity for garbage generation and garbage collection.  The
> call to maybe_pure_coordinate() estimates positions for everything in the
score,
> which causes a lot of computation and memory use.
> 
> Adding the two tracer printf()s below, I see a SCM object holding the skyline
> for the "Presto" is returned, then two hundred twenty three other skylines are
> created, side-positioned, and discarded,

Independent of this issue, this seems, uh, excessive?

> then the pointer into the skyline for
> the "Presto" is accessed.

I think that the C++ memory allocator is independent of the Scheme
allocator (ly:format uses scm_malloc so it may garbage collect when
memory is tight, but that seems about the only use of scm_malloc).  So
as long as the skylines calculated in between are not smobbed (turned
into Scheme objects), the Scheme garbage collector has no incentive to
run.

Some Scheme objects, however, are allocated whenever a symbol is
encountered for the first time, so there are a lot of code paths that
seem safe from triggering garbage collection _except_ when they are
run for the first time.  While most symbols used via get_property or
similar are already somewhere present in permanent Scheme code (and
thus the symbols themselves are already allocated), the memoizing
construct used internally by get_property enters them into a weak hash
table to make sure they have a reference.  Maintenance of that weak
hash table can still cause a Scheme allocation on the first run
through.

In short: it's just not a good idea to rely on no Scheme allocations
in a non-trivial code passage.  At any rate, the circumstances of this
patch seem sufficient for retesting current master.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b