ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Taco Hoekwater <taco@elvenkind.com>
Subject: Re: Filling forms
Date: Tue, 06 Sep 2005 16:47:20 +0200	[thread overview]
Message-ID: <431DABF8.8070209@elvenkind.com> (raw)
In-Reply-To: <431D9712.5060107@logosrl.it>



Hi Luigi,

It is hard to benchmark stuff without the actual dataset, but I
have some hints that may help you. (I hope my prose is not too
confusing).


luigi.scarso wrote:
> Hi, I'm working on a project that require filling forms.
> Every field has  (x,y,width,height) dimension and
> ui=(barcode,texEdit) type (textEdit has some attributes too)

I would have used two separate macros then, one for barcodes
and one for textEdit. More macros that each do less is generally
faster than fewer macros that do more.

If you have 200 fields, don't be scared to define 200 named
macros for them


> 
> \def\Field[#1]{%
> \bgroup
> \getparameters[!!][#1]%% collect key/val

You could use \rawgetparameters in this kind of input. It is a
lot faster and you have complete control over spaces in the
input, so there is no need to use the slower \getparameters.

> %
> %
> %%%% textEdit
> \doifsamestring{\!!ui}{textEdit}{% text field

\doifsamestring is quite slow. A faster solution: most arguments
can only be one or two different things, right? Then you can
predefine a macro for the possible cases, say \dotextEdit and
\dobarcode, and replace most of the body of the \Field command
with

   \getvalue{do\!!ui}


I would suggest you try to do this pre-defining trick for all things
you can possibly get away with.  String comparisons in macro code
are very expensive compared to the C lookup times for macro names.
Another example:

  \doifsamestring{\!!para@hAlign}{left}{%
    \hbox to \!!w {\getvalue\s!dummy \vphantom{K} \getvalue\!!name \hss}%
  }%

is a lot slower than:

  \def\parahAlignleft{% in the preamble
    \hbox to \!!w {\getvalue\s!dummy \vphantom{K} \getvalue\!!name \hss}%
  }

followed by

   \getvalue{parahAlign\!!para@hAlign} % in actual code


What is that \getvalue\s!dummy doing there, btw? I don't see what
purpose it serves.


You can also gain a considerable bit of speed by using an explicit
\hrule with the correct size, instead of \vphantom{K}. Or just put
the dimensions in a global \hbox beforehand:

   % in the preamble
   \newbox\Kbox
   \setbox\Kbox=\hbox{\vphantom{K}}
   \def\parahAlignleft{%
    \hbox to \!!w {\getvalue\s!dummy \copy\Kbox \getvalue\!!name \hss}%
   }


Oh, and grouping is also slow. Why would you bother restoring stuff
if you will overwrite the values before the next use ? There is no
need for \bgroup ...\egroup around the pages if every page defines
every field anyway.


I'm quite confident that a near-optimal solution will look like this:


	... lots and lots of macro defs,
         \starttext
          %% Some 200 \getvalue  calls
         \getvalue{codicearticolo_len6}{957803}
         \getvalue{barcode_codice___matricola}{*9F9578030052201312*}
         \page


Final trick: when in doubt, run TeX with

   \tracingall \tracingonline=0

in the preable, on an input file of just a few pages. The general rule
of thumb is: the smaller log file, the faster the 'real' run will be.


I hope this helps,

Taco

  reply	other threads:[~2005-09-06 14:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-06 12:59 strange behaviour of colors Mojca Miklavec
2005-09-06 13:18 ` Filling forms luigi.scarso
2005-09-06 14:47   ` Taco Hoekwater [this message]
2005-09-06 15:09     ` luigi.scarso
2005-09-06 13:46 ` strange behaviour of colors luigi.scarso
2005-09-06 14:42   ` Mojca Miklavec
2005-09-06 16:11 ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=431DABF8.8070209@elvenkind.com \
    --to=taco@elvenkind.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).