1

While developing some package I end up with a dilemma:

  1. either a small number of TeX groups but many scratch variables
  2. or a small number of scratch variables but many TeX groups

I have the impression that solution 1 is much more frequent that solution 2. But during development, I find solution 2 much stronger.

On first thoughts, using TeX groups may have a higher computational cost, but how much? Are there some other criteria to choose between 1 or 2?

  • Why don't you benchmark it? – user202729 May 03 '22 at 07:55
  • 1
    as far as I can tell, a group itself is very low cost but a local definition within a group forces the outer value to be stored in the save stack so has some costs, so question is not how many groups but how many definitions within the group. Probably depends on lots of details, safest is to implement both and benchmark.... – David Carlisle May 03 '22 at 07:55
  • Actually, I think the reason 1 is more frequent than 2 is that usually you pass user code in (e.g. in the expl3 map functions), and the user code expects to be run outside any group. TikZ programming layer does not assume that. – user202729 May 03 '22 at 07:55
  • Alternatively, things like \__tl_analysis does not run any user code, so it locally creates a group without any problem. – user202729 May 03 '22 at 07:55
  • 2
    I agree with David. It heavily depends on what you are doing inside the group. You can famously kill TeX by doing {\setmathfont{...}} when using unicode-math due to the enourmous number of local definitions. – Henri Menke May 03 '22 at 08:31

0 Answers0