Hi all,
I have a question understanding what really happens when you define
functions.
I have this function:
compileSegment =
#(define-void-function (parser location segment)
(ly:music?)
; don't do anything if we're not compiling a segment file
(if (defined? 'isSegment)
(let ((book
#{ \book { \score { \new Staff \new Voice { \bar "" $segment } } } #} ))
(ly:book-process book #{ \paper {} #} #{ \layout {} #}
(ly:parser-output-name parser)))))
which takes a music expression and compiles a standalone pdf from it.
(We use this to create mini scores of the snippet we're working on,
without having to compile the full score each time).
Now I realized that my implementation is in a way extremely inefficient:
Of course each segment file includes the file with this function
(otherwise it couldn't be compiled standalone).
That means that when I compile the score the file is included and the
function defined and executed once _for each segment file_, that is:
around 5.000 times! In that mode the function stops at the if clause and
returns wihtout doing much, but it is called anyway.
I'm thinking of changing the approach completely and purging all that
stuff from the segment files (to create the standalone file one would
instead compile another file that contains a function which actively
fetches the content one is interested about.
But I'd only want to do that if it really matters performance-wise.
So can anybody please tell me what happens in the following pseudo-code
situation:
a.ily:
compileSegment = #(define-void-function)
b1.ily:
\include "a.ily"
music-1 = {}
\compileSegment \music-1
---
b2.ily:
\include "a.ily"
music-2 = {}
\compileSegment \music-2
score.ly:
\include "b1.ily"
\include "b2.ily"
music = {
\music-1
\music-2
}
...
As I see from --verbose output a.ily is accessed whenever b bN.ily file
is included.
So I think the following happens:
- bN.ily is included
- a.ily is included -> compileSegment is defined
-> compileSegment is called (and runs into the empty conditional expression)
Am I right that the compileSegment function is defined newly each time?
Does this replace the previous function or do I end up with n copies of
the function?
And finally: Can I expect significant performance improvements when I
remove all that \compileSegment stuff from the bN.ily files? Remember,
we're talking about about 5.000 files here.
Thanks for any enlightenment
Urs
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user