
nick at ccl4
May 21, 2008, 3:49 AM
Post #7 of 9
(123 views)
Permalink
|
|
Re: [perl #54186] IO::Seekable + POSIX -> constant subroutines redefined
[In reply to]
|
|
On Sat, May 17, 2008 at 12:10:28AM +0100, Nicholas Clark wrote: > On Sat, May 17, 2008 at 01:01:23AM +0200, Sbastien Aperghis-Tramoni wrote: > > Nicholas Clark wrote: > > > > >POSIX.xs had this code in AUTOLOAD, to call into POSIX::int_macro_int > > > > > > if ($NON_CONSTS{$constname}) { > > > my ($val, $error) = &int_macro_int($constname, $_[0]); > > > croak $error if $error; > > > *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) }; > > > } else { > > > > Isn't this the standard way constant are handled by ExtUtils::Constant? > > No. It's not a constant function. It's 5 macros that process arguments, > wrapped in a single C function. I can't count. It's 6, not 5. Anyway, I removed int_macro_int with change 33896, and improved the XS with change 33897 Change 33896 by nicholas[at]mouse-mill on 2008/05/21 09:18:00 Eliminate POSIX::int_macro_int, and all the complex AUTOLOAD fandango that creates closures round it. Instead, wrap WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WSTOPSIG and WTERMSIG directly with XS. The shared library is slightly larger, but dynamic memory usage savings beat this, even within one thread of one process. Simpler code too. Change 33897 by nicholas[at]mouse-mill on 2008/05/21 10:31:32 Replaced the WEXITSTATUS, WIFEXITED, WIFSIGNALED, WIFSTOPPED, WSTOPSIG and WTERMSIG wrappers with one wrapper using the XS "ALIAS" feature. This gets the shared object size back below the size before the removal of int_macro_int. It looks like there are other space savings to be made this way. I think I spent a bit more time on my code to measure the memory usage of the old and new (attached)approaches. (attached as posix.pl, along with before and after output.) By swapping from 6 XS wrappers to 1 using "ALIAS", change 33897 made the shared library shrink from 105944 to 105784 bytes. There are other similar savings to be made in POSIX.xs, and probably in other core XS code. This could make an "interesting" "cage-cleaner" type TODO task, if anyone's game. Bottom line of the two changes is that comparable memory usage from use POSIX; drops from 153606 to 152563 bytes, and if one actually uses all 6 functions, from 153641 to 152563 bytes. There's no AUTOLOAD now, so there's no change in memory on running them. Oh, and they run fewer ops, so will be faster too. See the script for the explaination of the games needed to cope with AUTOLOADed stubs causing Devel::Size to see things in other packages. Only user visible change is that if you call the 6 with too many arguments you now actually get an error: Was: $ ./perl -Ilib -MPOSIX -we 'WEXITSTATUS(3,2,3)' $ Now: $ ./perl -Ilib -MPOSIX -we 'WEXITSTATUS(3,2,3)' Usage: WEXITSTATUS(status) at -e line 1. Is this fair game to inflict on buggy users of 5.10.0? Nicholas Clark
|