-
Notifications
You must be signed in to change notification settings - Fork 513
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
[OPTIMISATION] Python method implemented in JS: improving them ? #2306
Comments
…d for lists, tuples or dicts. Rewrite list.__init__(), as reported in issue #2306.
I agree with your comments on Here is the new version list.__init__ = function(){
var $ = $B.args('__init__', 1, {self: null}, ['self'], arguments, {},
'args', 'kw'),
self = $.self,
args = $.args,
kw = $.kw
if(args.length > 1){
throw _b_.TypeError.$factory('expected at most 1 argument, got ' +
args.length)
}
if(_b_.dict.__len__(kw) > 0){
throw _b_.TypeError.$factory('list() takes no keyword arguments')
}
while(self.length > 0){
self.pop()
}
var arg = args[0]
if(arg === undefined){
return _b_.None
}
var pos = 0
for(var item of $B.make_js_iterator(arg)){
self[pos++] = item
}
return _b_.None
} I honestly don't remember why |
Thanks for your answer, it helps me understand Brython internals. What do you think of an |
I agree. Could you implement it for |
If const __args__init__ = generateArgs("__init__", "self, *args, **kw"); // compute it only once.
list.__init__ = function(){
const {self, args, kw} = $B.args0(__args__init__, arguments); // use new optimized function for parsing.
//....
} would replace list.__init__ = function(){
var $ = $B.args('__init__', 1, {self: null}, ['self'], arguments, {},
'args', 'kw'),
self = $.self,
args = $.args,
kw = $.kw
//...
} @PierreQuentel What do you think ? Should I work on it also ? |
Oh I didn't saw your message. I'll first make a |
Hi,
I noticed that some Python method were implemented in JS like that:
I'm seeing different issues with that:
$foo()
and an externalfoo()
, but other hasn't.$B.$call($B.$getattr())
is costly and do some copies / checks we might not need internally.Hence, I suggest the following:
1./2. Add a
addMethod()
functionThis will slow down a little Brython initialization, but I don't think it'll be significant compare to the python source parsing.
However, this would :
3. Why using
$B.$call($B.$getattr())
and not call the internal directly ?4. Internally speed up iterations by several means :
getAll()
internal function that'd allow to get all element from the iterable, if it is an array, would directly return the array.Symbol()
as a sentinel (is it faster than exception ???) OR having an internalhasNext
orisEmpty
function ? :@PierreQuentel What do you think ?
Cordially,
The text was updated successfully, but these errors were encountered: