Automatically loading the page state, LoadPageState
Hi, I wonder if it's necessary to manually load the MetaPost variables using LoadPageState. Some of them are static and do not require an update on each page, e.g. NOfPages, but many of them might change on each page, e.g. OnOddPage, PageNumber, TextWidth. Forgetting to use LoadPageState easily results in perfectly valid code producing wrong results, which might not be hard to spot. Example: \setuplayout [width=10cm] \showframe \starttext \startMPcode fill unitsquare xyscaled (\the\textwidth, 2cm); \stopMPcode \startMPcode fill unitsquare xyscaled (TextWidth, 2cm); \stopMPcode \startMPcode LoadPageState; fill unitsquare xyscaled (TextWidth, 2cm); \stopMPcode \stoptext I assume it's too inefficient to load the page state automatically for each graphic. However, loading the page state automatically is simple: \startMPinitializations LoadPageState; \stopMPinitializations Marco
On 2013–10–01 Marco Patzer wrote:
Hi,
I wonder if it's necessary to manually load the MetaPost variables using LoadPageState. Some of them are static and do not require an update on each page, e.g. NOfPages, but many of them might change on each page, e.g. OnOddPage, PageNumber, TextWidth.
@Hans: How about adding some more of the dynamic variables to the MPinitializations in meta-ini.mkiv? Marco
On 10/1/2013 2:36 PM, Marco Patzer wrote:
On 2013–10–01 Marco Patzer wrote:
Hi,
I wonder if it's necessary to manually load the MetaPost variables using LoadPageState. Some of them are static and do not require an update on each page, e.g. NOfPages, but many of them might change on each page, e.g. OnOddPage, PageNumber, TextWidth.
@Hans: How about adding some more of the dynamic variables to the MPinitializations in meta-ini.mkiv?
like what anyway, \starttext \startMPcode \stopMPcode \testfeatureonce{1}{\startMPcode for i=1 upto 1 : LoadPageState ; endfor ; \stopMPcode} \testfeatureonce{1}{\startMPcode for i=1 upto 10 : LoadPageState ; endfor ; \stopMPcode} \testfeatureonce{1}{\startMPcode for i=1 upto 100 : LoadPageState ; endfor ; \stopMPcode} \testfeatureonce{1}{\startMPcode for i=1 upto 1000 : LoadPageState ; endfor ; \stopMPcode} \testfeatureonce{1}{\startMPcode for i=1 upto 10000 : LoadPageState ; endfor ; \stopMPcode} % LoadPageState defined: % system > starting feature test % system > feature test done (0.001s) % system > starting feature test % system > feature test done (0.001s) % system > starting feature test % system > feature test done (0.002s) % system > starting feature test % system > feature test done (0.021s) % system > starting feature test % system > feature test done (0.210s) % Directly set variables % system > starting feature test % system > feature test done (0.001s) % system > starting feature test % system > feature test done (0.001s) % system > starting feature test % system > feature test done (0.000s) % system > starting feature test % system > feature test done (0.001s) % system > starting feature test % system > feature test done (0.002s) \stoptext in mkiv the overhead is less than in mpii as we don't parse the blob in the same way and the mpiv code is also more optimized so we can consider dropping the SetPageState macro. Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 2013–10–01 Hans Hagen wrote:
in mkiv the overhead is less than in mpii as we don't parse the blob in the same way and the mpiv code is also more optimized so we can consider dropping the SetPageState macro.
I see you decided to drop LoadPageState. It's about 20ms overhead per 1000 graphics, which is negligible, I'd say. Thanks for making ConTeXt easier to use and more predictable. Marco
On 10/1/2013 8:35 PM, Marco Patzer wrote:
On 2013–10–01 Hans Hagen wrote:
in mkiv the overhead is less than in mpii as we don't parse the blob in the same way and the mpiv code is also more optimized so we can consider dropping the SetPageState macro.
I see you decided to drop LoadPageState. It's about 20ms overhead per 1000 graphics, which is negligible, I'd say. Thanks for making ConTeXt easier to use and more predictable.
well, it's an experimental patch so we'll see (btw, it's less neglectable when you run context on a mobile phone -) Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On 10/1/2013 2:15 PM, Marco Patzer wrote:
Hi,
I wonder if it's necessary to manually load the MetaPost variables using LoadPageState. Some of them are static and do not require an update on each page, e.g. NOfPages, but many of them might change on each page, e.g. OnOddPage, PageNumber, TextWidth. Forgetting to use LoadPageState easily results in perfectly valid code producing wrong results, which might not be hard to spot. Example:
sure, but a 'many' versus 'some' distinction is too fuzzy
\setuplayout [width=10cm] \showframe \starttext \startMPcode fill unitsquare xyscaled (\the\textwidth, 2cm); \stopMPcode
\startMPcode fill unitsquare xyscaled (TextWidth, 2cm); \stopMPcode
\startMPcode LoadPageState; fill unitsquare xyscaled (TextWidth, 2cm); \stopMPcode \stoptext
I assume it's too inefficient to load the page state automatically for each graphic. However, loading the page state automatically is simple:
Indeed. an option is to hook into setuplayout and signal changes but this is never 'quick patch' code and I don't want to be bitten by it so I need to test such hacks myself first (in real tests).
\startMPinitializations LoadPageState; \stopMPinitializations
btw, normally I do StartPage() StopPage() when I do something that relates to the page (and most of those runtime graphics don't relate to the page at all) so, more a "something i can look into" than "a quick hack" Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Marco Patzer