Hi, Gunther!

> Is there any way to add an interface to basically provide
> serialization and 
> deserialization hints? My experience in the way we use SOAP is that
There is no way to ptovide hints, but you have several options to
alter serializer/deserializer and use all other infrastructure. For
example, you may override serializer completely from scratch and then
register it with:

my $soap = SOAP::Lite->serializer(My::Serializer->new)->.......

Or you may inherit your own serializer and specify it in the same
way. The same thing is true about deserializer and about server side
(these methods are available there also).

I did some tests with overriding serializers and truly results are
surprised me at least a little bit. Script is below. Results:

o - (1)x200: 23 wallclock secs (23.68 usr +  0.00 sys = 23.68 CPU) @ 
4.22/s (n=100)
o - (1x100)x200: 25 wallclock secs (24.99 usr +  0.00 sys = 24.99
CPU) @  4.00/s (n=100)

a - (1)x200: 15 wallclock secs (15.33 usr +  0.00 sys = 15.33 CPU) @ 
6.52/s (n=100)
a - (1x100)x200: 16 wallclock secs (16.14 usr +  0.00 sys = 16.14
CPU) @  6.20/s (n=100)

t - (1)x200:  6 wallclock secs ( 5.11 usr +  0.00 sys =  5.11 CPU) @
19.57/s (n=100)
t - (1x100)x200:  6 wallclock secs ( 6.15 usr +  0.00 sys =  6.15
CPU) @ 16.26/s (n=100)

x - (1)x200:  2 wallclock secs ( 2.08 usr +  0.00 sys =  2.08 CPU) @
48.08/s (n=100)
x - (1x100)x200:  3 wallclock secs ( 3.19 usr +  0.00 sys =  3.19
CPU) @ 31.35/s (n=100)

First is default serializer. 

Second makes serialization only for first element of array and then
duplicates the results, emulating procedure for one type for all
elements. 50% better

Third generates ready to use xml and provides it as the result (you
may provide xml fragments during serialization) using serializer's
tag function. Almost 5 times better comparing to default.

Forth generates xml with by-hand coding. Almost 10 times better than
default. Everithing else is generated by serializer, so you can
insert your fragment seamlessly.

It's definitely something to think about. I'll take a closer look,
but it shows that having some information about data structure you
may significantly speed up this process. You may alter serialization
depending on user-defined class, depending on Object class, depending
on ref type (array, hash, scalar), etc., so you have almost full
control on serializer behavior. Create you own, override what you
need, register it and you're done.

Here is the script

# -- -- -- -- -- -- -- -- -- -- --

use SOAP::Lite;

use Benchmark;

$s = SOAP::Serializer->new;
$a = My::Serializer::Array->new;
$x = My::Serializer::XML->new;
$t = My::Serializer::XMLtag->new;

$array1 = [(1) x 200];
$array100 = [(1x100) x 200];

Benchmark::timethese(100, {
  'o - (1)x200' => sub { $s->method(a => $array1) },
  'o - (1x100)x200' => sub { $s->method(a => $array100) },
  'a - (1)x200' => sub { $a->method(a => $array1) },
  'a - (1x100)x200' => sub { $a->method(a => $array100) },
  'x - (1)x200' => sub { $x->method(a => $array1) },
  'x - (1x100)x200' => sub { $x->method(a => $array100) },
  't - (1)x200' => sub { $t->method(a => $array1) },
  't - (1x100)x200' => sub { $t->method(a => $array100) },
});

BEGIN {

  package My::Serializer::Array;

  @My::Serializer::Array::ISA = 'SOAP::Serializer';

  sub encode_array {
    my($self, $array, $name, $type, $attr) = @_;
    my $items = 'item'; 

    my @items = ($self->encode_object($array->[0], $items)) x
@$array;

    return [$name || '~C:Array', {%{$attr || {}}, '~C:arrayType' =>
$arraytype, 'xsi:type' => SOAP::Utils::qualify('~C' => $type)},
[@items], $self->gen_id($array)];
  }

  package My::Serializer::XML;

  @My::Serializer::XML::ISA = 'SOAP::Serializer';

  sub encode_array {
    my($self, $array, $name, $type, $attr) = @_;

    my $items = join '', '<Array>', map("<item>$_</item>", @$array),
'</Array>';

    return [$name, {'_xml' => 1}, $items];
  }

  package My::Serializer::XMLtag;

  @My::Serializer::XMLtag::ISA = 'SOAP::Serializer';

  sub encode_array {
    my($self, $array, $name, $type, $attr) = @_;

    my $items = join '', '<Array>', map($self->tag('item', {}, $_),
@$array), '</Array>';

    return [$name, {'_xml' => 1}, $items];
  }
}

# -- -- -- -- -- -- -- -- -- -- --

Hope it gives you some ideas.

Best wishes, Paul.

--- Gunther Birznieks <[EMAIL PROTECTED]> wrote:
> At 05:14 PM 2/24/2001 -0800, Paul Kulchenko wrote:
> >That's right, but first Perl caches calls that involve inheritance
> >and second, I use the same scheme, because arrays can have
> everything
> >inside and I need to call serialization function for every element
> in
> >array. I did profiling for several versions and did some
> >improvements, but there is no obvious stopper.
> 
> Is there any way to add an interface to basically provide
> serialization and 
> deserialization hints? My experience in the way we use SOAP is that
> there 
> are only a few core objects that really require SOAP and the rest
> can be on 
> the front-end.
> 
> Maybe using a CORBA-like IDL config? Thus, I could give a strong
> hint to 
> SOAP::Lite that a particular array only contained one type of
> object...
> 
> In the stuff I've been doing over the last year, I've always wrote
> my own 
> serializer/deserializer from scratch because I wanted it to be fast
> and 
> have control over optimization rather than using the libraries that
> already 
> exist out there.
> 
> Later,
>     Gunther
> 


__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/

Reply via email to