[GAP Forum] Forum discussion on packages and global function names

Steve Linton sal at cs.st-and.ac.uk
Tue May 1 12:31:31 BST 2007


Dear GAP Forum,

Yevgen Muntyan's post and the discussion which follows raise the question of
managing the global variable namespace as the number of packages in GAP grows. 

Some guidelines in this direction appear on the Web site at
http://www.gap-system.org/Packages/Authors/variablenames.html. 

To answer specifically Yevgen's question: 

> Should packages use operations as much as possible? 

the answer, as explained on that page is "basically yes". Indeed, where
appropriate, Attributes should even be preferred to Operations. 

In the ensuing discussion, there was some concern about performance costs of
method selection. As someone else pointed out, this is very small. On my laptop
(Pentium M 2.1 GHz) the cost of calling a one argument function that does
nothing as a method of an operation is about 20ns more than calling it
directly (about 100ns per call, vs about 80). Admittedly this is the ideal
situation
(since there are no other methods or calls to this operation, my method is
sure to be first in the cache), but real life should get pretty close to this.
GAP caches the last few sets of argument types with which an operation has
been called and checks them first. Almost all operation calls are cache hits.

Unless you have very clear evidence that it is a problem then, I would suggest
that programming around the method selection system is likely to complicate
your code without gaining you much performance. It can be helpful to also
store your methods in global functions for debugging or profiling purposes,
but in this case you should certainly either (a) use "non-obvious" names, or
(b) remove these assignments from the released version of your package.

I should say that there is one awkward exception to this generally good
performance, namely when one of the arguments is a plain list with mutable
entries. In this case determining its type must be repeated at every operation
call, and can be expensive. We have some longer term plans to address this,
but thy will involve significant changes and will take a while to work through.

We have discussed the idea of introducing some version of namespaces into GAP,
but nothing is currently planned.

	Steve Linton
-- 
Steve Linton	School of Computer Science  &
      Centre for Interdisciplinary Research in Computational Algebra
	     University of St Andrews 	 Tel   +44 (1334) 463269
http://www.cs.st-and.ac.uk/~sal 	 Fax   +44 (1334) 463278   



More information about the Forum mailing list