-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added generateArgs() function #2308
base: master
Are you sure you want to change the base?
Added generateArgs() function #2308
Conversation
New method addMethod( list, __init__, "self, *args", {self: null}); // last argument is the default values. |
Got an idea for better perfs. Instead of having the internal function like : This would prevent having to build an object when calling the function internally. @PierreQuentel should I try to do it ? |
@PierreQuentel Tell me which one do you prefer, and I'll make a cleaner commit with parsing method generation (like we did for Solution 1 : more optimizedfunction foo(self, args_a, args_b,
varargs, // JS array
kwargs // JS object
){
// do stuff
}
addMethod(klass, foo, "self, args_a, args_b, *args, **kwargs");
foo(self, 1, 2, [3,4], {a: 34}); Solution 2 : less optimized, use $B.args0_NEWfunction foo({self, args_a, args_b,
varargs, // PY tuple
kwargs // PY dict
}){
// do stuff
}
addMethod(klass, foo, "self, args_a, args_b, *args, **kwargs");
foo({self, args_a: 1, args_b: 2,
varargs: $B.fast_tuple([3,4]),
kwargs: $B.obj_dict({a: 34})
}); |
I understand the options for Calls are constructed in |
For the internal function, yes. Like you already have both an internal and external functions for some methods. Internal functions doesn't do arguments parsing, and is like a shortcut when you use it internally. Whereas external calls do the argument parsing (so is a little slower).
foo(self, 1, 2, {}) // internal call (e.g. called from JS files like py_lists.js).
self.klass.foo(self, 1, 2, {$kw: [{}, {}]}) // external call (e.g. called from a Brython script).
// external calls is implemented like :
self.klass.foo = function(...args) { return foo(...parseArgs(foo, args) ) }
Interesting. Later, I'll have some optimizations to suggest in regard of it. Don't hesitate to give me some codes you want to benchmark (only using core features, without prints, DOM manipulations, or python libraries).
Yep, but you can adapt it little by little, changing one method at a time. The advantage, is that it should be very fast during execution time.
|
Did some benchmark (foo(i) / N=100000000), here the conclusions :
EDIT: This means that if you replace some current calls to internal calls, you might be at least 50x faster. |
Okay, did better benchmark
I cheated a little (shame on me) for some stuff I know will be solved by a parser generator. I didn't tested named argument but it should be faster :
So overall it shouldn't be slower, and should even be faster. @PierreQuentel I assume this is worthing it ? I also noticed that I missed some micro optimizations in |
This comment was marked as outdated.
This comment was marked as outdated.
Okay, so after further tests :
For 2., indeed, we can't do : klass.fooE = function() {
const result = $B.args0(__args__, arguments);
return fooE( result.i );
} automatically, so we must do something like : const argnames = ["i"];
klass.fooC = function() {
const result = $B.args0(__args__, arguments);
const args = new Array(argnames.length);
for(let i = 0; i < argnames.length; ++i)
args[i] = result[argnames[i]];
return fooC( ...args );
} |
New method
generateArgs(fct, name, args_str, defaults)
:Please do not merge yet, I'm working on
addMethod()
now.It is just for you to see
generateArgs()
.