develooper Front page | perl.perl5.porters | Postings from October 2009

Re: smaller globs

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
October 27, 2009 06:27
Subject:
Re: smaller globs
Message ID:
20091027132700.GZ60303@plum.flirble.org
On Tue, Oct 27, 2009 at 01:19:49PM +0000, Zefram wrote:
> Thinking about the const sub space optimisation.  I think we can do
> something similar more broadly.  Observe that most GVs only contain one
> type of item.  In these cases, the GP structure is wasteful.  We could
> optimise one-item GVs by referencing the item directly through svu_rv,
> instead of having a GP, and using about three flag bits to indicate which
> type of item it is (scalar, array, hash, IO, format, sub, const sub).
> The SVpad_ flag bits are conveniently available to reuse for this.

Are they? I thought that GVs can be stored in pads.

#define SVs_PADSTALE	0x00010000  /* lexical has gone out of scope */
#define SVpad_STATE	0x00010000  /* pad name is a "state" var */
#define SVs_PADTMP	0x00020000  /* in use as tmp */
#define SVpad_TYPED	0x00020000  /* pad name is a Typed Lexical */
#define SVs_PADMY	0x00040000  /* in use a "my" variable */
#define SVpad_OUR	0x00040000  /* pad name is "our" instead of "my" */

> Obviously, this compact structure would have to upgrade itself to a full
> GV with metadata and GP, if it's actually referenced as a GV.  This is

At that point, it can't know its line or file?

struct gp {
    SV *	gp_sv;		/* scalar value */
    struct io *	gp_io;		/* filehandle value */
    CV *	gp_cv;		/* subroutine value */
    U32		gp_cvgen;	/* generational validity of cached gv_cv */
    U32		gp_refcnt;	/* how many globs point to this? */
    HV *	gp_hv;		/* hash value */
    AV *	gp_av;		/* array value */
    CV *	gp_form;	/* format value */
    GV *	gp_egv;		/* effective gv, if *glob */
    line_t	gp_line;	/* line first declared at (for -w) */
    HEK *	gp_file_hek;	/* file first declared in (for -w) */
};

Offhand I can't remember where those are used.

> Sound sane?  If it's appealing, I'll investigate more closely where we
> can actually dispense with the metadata.

I'm not sure if it feels sane. Certainly, I'd firstly like to know where the
metadata ends up being read again.

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About