Hi Nick, calls to custom functions in AQL will mostly be slower than calls to native functions. The reasons for this are: - the AQL query optimizer cannot make any assumptions about custom functions, so it will not perform any optimizations it may be able to apply for built-ins. - custom functions run in JavaScript (using the V8 engine) so the input to the functions needs to be converted from the internal format to a V8-compatible format. When the function has calculated its result, there is again a conversion on the way back. Conversion is not that expensive for simple types such as booleans and numbers, but especially expensive for strings, which are UTF-16-encoded in JavaScript but UTF-8-encoded elsewhere. The problem is also apparent for objects, because the object's attributes/keys are strings as well.
This means that for the user-defined function variant of the query there will be a lot of work behind the scenes, whereas for the query without there will be much less: it does not call any functions at all, but use an object literal which only will be computed once for the whole query. This is of course much more efficient. User-defined functions can still be useful when applied on smaller amounts of data, especially as they allow things like control flow which is not available in regular AQL. Apart from that, the two queries given are not equivalent. The one with the custom function uses a variable named "map", which is not defined in the query itself. So the query will only work if there exists a collection named "map". In this case the whole collection contents will be loaded on every function call and passed into the user-defined function. The second query without the user-defined function does not use a variable named "map" anywhere. I hope this helps. Best regards Jan 2016-05-12 0:03 GMT+02:00 Nick Wolf <[email protected]>: > Hi ArangoDB Users, > > > I have been performance testing on custom functions and i find it very > slow. Is it expected or something tuning can be done here? > > Stats: > "Coll1" collection has 1.3million documents. > > Just to test the function call i have created a blank function which > returns a constant. > > require("org/arangodb/aql/functions").register("myfunctions::fun1", > function (cursor) { > return 10; > }); > > > *Following update statement takes 80Sec.* > > UPDATE outVertex WITH {value:myfunctions::fun1(map)} IN coll1 > > > *Following update statement takes 10Sec* > > UPDATE outVertex WITH {value:10} IN coll1 > > > -- > You received this message because you are subscribed to the Google Groups > "ArangoDB" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "ArangoDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
