Mailing List Archive

caching patch for Embperl 1.2.1 / 1.3b2
Gerald,

We have a function we use called includeexec that includes an Embperl
file and executes it, using the same namespace as the caller. We use
this all the time for stuff like this:

[+ $menu_item = 1; includeexec('menu.html'); +]

So menu.html tests the value of $menu_item and highlights the
appropriate menu item. (Or whatever else it needs to do.)

Here's the function:

sub includeexec($@)
{
my ($filename) = shift;
use HTML::Embperl;
my @param = @_;
my $body = '';

my ($package, $file, $line) = caller();

HTML::Embperl::Execute({inputfile => $filename,
output => \$body,
param => \@param ,
package => $package,
cleanup => 0});
return $body;
}


We ran into a problem where two different files include menu.html and
the namespace was being mismatched. Brian and I traced it to a
caching issue--once a particular file has been associated with a
particular namespace, Embperl will always execute that file in that
namespace, regardless of what you ask for.

After a couple false starts, we came up with the following. If the
requested namespace is different from the "associated" namespace, the
file is treated as if it has been modified, and is reloaded from disk
and re-executed. It's non-optimal, performance-wise, but it appears
to work.

The change is valid for 1.2.1, but it looks like it should apply to
1.3b2 as well.

Any thoughts on the best way to get back caching with the behavior we
want?


--- epmain.c.orig Mon Mar 27 14:28:20 2000
+++ epmain.c Mon Mar 27 14:27:53 2000
@@ -1668,9 +1668,16 @@
ppSV = hv_fetch(pCacheHash, (char *)sSourcefile, strlen (sSourcefile), 0) ;
if (ppSV && *ppSV)
{
+ int swap = 0;
f = (tFile *)SvIV((SV*)SvRV(*ppSV)) ;
-
- if (mtime == 0 || f -> mtime != mtime)
+
+ if (f->sCurrPackage != NULL &&
+ pConf->sPackage != NULL &&
+ strcmp(f->sCurrPackage, pConf->sPackage) != 0)
+ swap = 1;
+
+
+ if (mtime == 0 || f -> mtime != mtime || swap)
{
hv_clear (f -> pCacheHash) ;

@@ -1686,6 +1693,16 @@
SvREFCNT_dec (f -> pExportHash) ;
f -> pExportHash = NULL ;
}
+
+ if (swap)
+ {
+ lprintf (r, "[%d]MEM: Switch package name in %s from %s to %s\n",
+ r -> nPid, sSourcefile, f -> sCurrPackage, pConf->sPackage) ;
+ free(f->sCurrPackage);
+ f->sCurrPackage = strdup (pConf -> sPackage);
+ f->nCurrPackage = strlen(f->sCurrPackage);
+ }
+
}
}
else
RE: caching patch for Embperl 1.2.1 / 1.3b2 [ In reply to ]
Hi Todd,

>
> We have a function we use called includeexec that includes an Embperl
> file and executes it, using the same namespace as the caller.
>..
> We ran into a problem where two different files include menu.html and
> the namespace was being mismatched. Brian and I traced it to a
> caching issue--once a particular file has been associated with a
> particular namespace, Embperl will always execute that file in that
> namespace, regardless of what you ask for.
>

Yes

> After a couple false starts, we came up with the following. If the
> requested namespace is different from the "associated" namespace, the
> file is treated as if it has been modified, and is reloaded from disk
> and re-executed. It's non-optimal, performance-wise, but it appears
> to work.
>

Francis J. Lacoste has send me a patch for the same problem, two weeks ago.
His patch creates an cache for every filename/packagename combination. This
will perform better, but costs more memory. I think I will use this patch.

Anyway, thanks for the patch

Gerald

P.S. This shows how important it is, to send anything thru the list, to
avoid double work. For the Embperl users and for me

-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
RE: caching patch for Embperl 1.2.1 / 1.3b2 [ In reply to ]
Gerald Richter writes:
>Francis J. Lacoste has send me a patch for the same problem, two weeks ago.
>His patch creates an cache for every filename/packagename combination. This
>will perform better, but costs more memory. I think I will use this patch.

Oh, excellent. I thought that was The Right Thing, but didn't have
time to think about how to do it.

I'd be glad to try pounding on it for a while before you include it,
if you'd send it to me.


Todd
RE: caching patch for Embperl 1.2.1 / 1.3b2 [ In reply to ]
Hi Todd,

>
> I'd be glad to try pounding on it for a while before you include it,
> if you'd send it to me.
>

I just commited the patches to the CVS. If you like to try them either fetch
it via annonymous CVS or wait until a new tarball is generated at
http://perl.apache.org/from-cvs/embperl.

Gerald



-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925151
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------