[fpc-pascal] Improved FPC JSON-RPC support
Michael Van Canneyt
michael at freepascal.org
Wed Dec 29 10:54:03 CET 2021
On Tue, 28 Dec 2021, Don Duvall via fpc-pascal wrote:
> Has any performance tests been ran, to see what the runtime impact of
> utilizing RTTI is? Hopefully negligent in the grand scheme...
No tests have been run.
I also don't know what exactly you would compare it with ?
Using some plain common sense:
The 'older' json-rpc mechanism relied on TJSONRPCHandler components on a Datamodule.
Loading a datamodule and all components (one per exposed method) on it also
uses RTTI, but is bound to beslower due to all the loading & parsing
of the lfm file for every call.
Even so, all that will be dwarfed by the network latency & http+json protocol:
Many years ago, I did a speed comparison test of the various protocols
offered by Remobjects SDK in delphi. It was published in Toolbox magazine:
https://www.freepascal.org/~michael/articles/index.html#remobjects2
(the date on the article is misleading, it is actually older, must have been
2005 or so)
They showed clearly that the used protocol (http & xml) is the largest factor.
in 2013 I did many tests in a JSON REST framework: the times for streaming
were dwarfed by the time spent on network & database access.
Translated to RPC: if you want speed, don't use HTTP or JSON. WST offers a
binary protocol and plain TCP channel, it's bound to be much faster.
Michael.
>
> Thanks,
> Don
>
> On 12/28/2021 2:11 PM, Michael Van Canneyt via fpc-pascal wrote:
>>
>>
>> On Tue, 28 Dec 2021, Graeme Geldenhuys via fpc-pascal wrote:
>>
>>> On 2021-12-28 15:25, Michael Van Canneyt via fpc-pascal wrote:
>>>>
>>>> Thanks to the magic of RTTI and Invoke(), creating a JSON-RPC server
>>>> has
>>>> just become significantly easier !
>>>
>>> That's pretty neat - nicely done Michael.
>>
>> We do our best.
>>
>>>> // Create a class that implements the interface
>>>> Type
>>>> TIntf2Impl = class(TInterfacedObject, IMyOtherInterface)
>>>> public
>>>> function Echo(args: TStringArray): String;
>>>> function SayHello: string;
>>>> end;
>>>
>>> ...snip...
>>>
>>>> // Register the class using an interface factory:
>>>> Function GetMyOtherInterface(Const aName : string) : IInterface;
>>>> begin
>>>> Result:=TIntf2Impl.Create as IInterface;
>>>> end;
>>>
>>>
>>> Slightly off topic, and my Object Pascal is getting a bit rusty as
>>> the years go by. <grin> ;-) In your factory above, is the "as
>>> IInterface" part needed. Can't the FPC compiler automatically cast
>>> the return type based on the function return type, and the fact that
>>> the compiler should know that TIntf2Impl type implements
>>> TInterfacedObject?
>>
>> No, theoretically it probably could, but type inference is not
>> implemented in Pascal.
>>
>> Michael.
>>
>> _______________________________________________
>> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
>> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list