[Xapian-devel] PHP Latest

Daniel Ménard Daniel.Menard at Bdsp.tm.fr
Wed Apr 19 12:23:29 BST 2006


Olly Betts a écrit :

>(19/04/2006 04:45) Latest version:
>  
>
Ouah, it's moving really fast !
[ BTW, looking at your mail's time, it looks like you didn't sleep a 
lot, that night ;-) ]

>The "swig_coerce_param" helper has gone!  I had a look at Sam's
>suggestion to do this in the wrapper code, and it's actually very
>easy.  
>  
>
SWIG is really a great software to allow such a degree of flexibility. 
I'm really impressed!

>Currently the arguments are just called $arg0, $arg1 (...)
>I just wanted to avoid having to worry for now about names 
>being invalid in PHP or clashing with something.
>  
>
C++ and PHP syntax for naming identifiers are quite similar, and unlike 
functions names which can clash (as you already know : empty, clone...), 
I don't think there are "reserved" variables names in PHP, so it 
probably won't clash with anything, and it would be a nice bonus to have 
real parameter names.

>It's also unclear what to do for overloaded methods if a parameter
>name varies in each overloaded version.  Perhaps call it
>"$foo_or_bar_or_baz" if it has names "foo", "bar", and "baz" in
>different overloads?
>  
>
This is the approach I took in my wrapper e.g.: 
deleteDocument($docID_or_term)

>Could you try timing this one?  I suspect it'll be much nearer your
>hand-coded wrappers in performance.
>  
>
I updated my test to include version 5 and 6 of the wrappers. I first 
tested with version 0.9.4 of xapian (using original version of 
xapian_wrap.cc), then I built version 0.9.5 of core, replaced 
xapian_wrap.cc with the new xapian_wrap6.cc, built the bindings, 
restarted apache and ran the test again.

Remember that the code only tests 3 functions (new_document, 
document_set_data and document_add_posting) :
http://www.bdsp.tm.fr/aed/xapian/call_test.php.txt

in previous test we had :
- native calls to the xapian flat functions : 8.88 seconds
- my wrapper : 13.88 sec
- swig's wrapper, first version : 37.54 sec

new test with version 0.9.4
- wrapper version 5 : 24.44 sec
- wrapper version 6 : 24.17 sec

with version 0.9.5
- native calls to the xapian flat functions : 9.32 secs
- my wrapper : 14.45 sec
- first version of the swig's wrapper : 39.30 sec
- wrapper version 5 : 25.66 sec
- wrapper version 6 : 25.34 sec

By getting rid of coerce_param in the PHP code, you got a 14 seconds 
gain (39.30 vs 25.34), which is a big win, and the new xapian_wrap.cc 
which now do some coercion is not significantly slower (9.32 vs 8.88), 
but it seems that call_user_func_array and/or 
func_get_args+array_unshift are not very optimized (25.34 vs 14.45)

I tried to play with the php code in the wrapper, testing with different 
versions of add_posting :

func_get_args+array_unshift, direct call : exec time=21.04 sec
    public function add_posting($arg0,$arg1,$arg2) {
        $a=func_get_args();
        array_unshift($a,$this->swig_ptr);
        Document_add_posting($this->swig_ptr, $arg0,$arg1,$arg2);
    }

small array, call_user_func : exec time=23.35 sec
    public function add_posting($arg0,$arg1,$arg2) {
        $a=array($this->swig_ptr, $arg0, $arg1, $arg2);
        call_user_func_array('Document_add_posting',$a);
    }

direct call only : exec time=14.42 sec
    public function add_posting($arg0,$arg1,$arg2) {
        Document_add_posting($this->swig_ptr, $arg0,$arg1,$arg2);
    }

So it seems that this is the creation of a temporary array for handling 
the parameters (either with get_func_args or with array) which takes 
time. Too sad it makes such a difference...

>Functions/methods with no optional parameters and the same number of
>parameters in each overload now get parameter lists instead of using
>func_get_args and call_user_func_array.  
>  
>
>I don't think we know the default values in SWIG (...)
>  
>
I can imagine that it will be difficult to have parameter lists for 
*all* functions because of overloading...
But perhaps the "with no optional parameters" condition could be 
removed, handling optional parameters as non-optional ones ?
For example, we would get function add_posting($tname, $tpos, $wdfinc), 
which would require to always pass the wdfinc argument.
Or perhaps we could generate function add_posting($tname, $tpos, 
$wdfinc=null)
(i.e. null as default value for all optional parameters), with the c 
wrapper doing some magic like "if arg is null, don't pass it to xapian".. ?
[ enough perhaps, I don't know what I'm speaking about ;-) ]

>Now there's just swig_wrap_return.  It could be a static method of the
>base class actually, but I wonder if it's not better to just inline a
>conversion to the known return type (except in the case of overloaded
>methods with covariant return types perhaps).
>Another way to approach it might be to postprocess Doxygen's XML output
>(which would allow mechanical changes to match PHP syntax).
>  
>
I would go for the static method...

>>[...] it'd also be interesting to check the timings with instanceof
>>instead of is_a
>>[...] this is no longer very interesting
>>    
>>
just for the record, I tested 'is_a' against 'instanceof' in the 
original wrapper. InstanceOf is winning :
- is_a : 48.52   48.43
- instanceof : 39.17 (tests I made above with the original wrapper were 
using instanceof to get rif of the warnings)

>Another way to approach it might be to postprocess Doxygen's XML output
>(which would allow mechanical changes to match PHP syntax).
>  
>
Looks like an interesting approach. I will try to give it a try if I can.

I will also try to think about having native php iterators...
As Paul said in a previous mail, we will have to implement the iterator 
(or perhaps the Iterator Aggregate) interfaces, but we can also have to 
add new methods (for example : for each method like "xxx_begin", add a 
new method "xxx" wich return the php iterator), so one can write
foreach ($document->values() as $no=>$value) echo "$no : $value\n";

Would it be possible to generate this kind of arbitrary stuff with SWIG ?

Best regards,

-- 

Daniel Ménard

Banque de Données Santé Publique
Avenue du Professeur Léon Bernard
35043 Rennes Cédex

Tél. (+33) 2.99.02.29.42
Fax (+33) 2.99.02.26.28
E-mail Daniel.Menard at Bdsp.tm.fr
http://www.bdsp.tm.fr




More information about the Xapian-devel mailing list