[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-hackers] [PATCH] Re-use argvectors in generated code
From: |
Peter Bex |
Subject: |
[Chicken-hackers] [PATCH] Re-use argvectors in generated code |
Date: |
Sun, 30 Aug 2015 20:34:11 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Hi all,
Felix already hinted that this might be a possibility, so I decided to
try re-using argvectors instead of allocating a new argvector whenever
a function gets called. This turned out to be remarkably easy to do.
Basically, if your function's argvector is at least as big as the
function you're going to call, you can just stick the arguments for
the callee in your own argvector and pass *it* instead. Because functions
which accept argvectors never return (and also because we copy all
argvector objects into temporary local variables), it is safe to do this.
The attached patch emits code that determines this dynamically. I've
also tried keeping the vector statically allocated and declare it as a
pointer to the original av when the argument count is larger (which we
know inside the compiler), but this didn't prove to be any faster.
I dedided to use the dynamic version because in this case, we have a
slightly higher chance of being able to re-use the argvector when the
caller is a vararg function; then the rest args can be the decisive
factor when determining to reuse.
Attached is also the benchmark difference between master with this
patch and 4.10.1 (which also uses argvector); as you can see it's not
making much of a difference (and that may just be noise). The numbers
egg's benchmarks suggest it does help in reducing the number of GCs,
though. Still, not as good as I hoped.
The attached patch applies to master and chicken-5. For good results,
please first apply the off-by-one fix I mailed earlier.
Finally, we might be able to win even more by storing the argvector's
length separately from the argcount (but this would imply another binary
incompatibility change!): this would allow mutually recursive procedures
with different argcounts to re-use their argvector all the way. Right
now, if a procedure with 3 arguments calls a procedure with 2 arguments
while reusing its argvector, and that procedure calls a procedure with
3 arguments, it'll allocate a fresh argvector, even though the original
argvector had a size of 3 arguments. That's because when calling the
2-arg function, it receives an argcount of 2, and must assume that the
argvector is only big enough to contain 2 arguments.
I think using a single global argvector might speed things up more, but
that's an even bigger change of course. This argvector would only have
to be reallocated when the number of arguments is higher (or much smaller)
than the last call. But let's try that later. Argvectors are a big
enough change as it is, and I don't want to overhaul both master and
chicken-5 like this again.
Cheers,
Peter
0001-Dynamically-determine-if-we-can-re-use-argvectors.patch
Description: Text Data
benchmark-diff.txt
Description: Text document
signature.asc
Description: Digital signature
- [Chicken-hackers] [PATCH] Re-use argvectors in generated code,
Peter Bex <=