-
Notifications
You must be signed in to change notification settings - Fork 510
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
[CODE CLEANING/OPTI/BUG FIX] Improve List/Tupple/Array conversions #2299
Comments
For That'd be a little troublesome at first, but maybe the cleaner way to proceed. EDIT: Or use the magic solution: a proxy. Built in a way to ignore non-string keys. Again, it'll kill performance in the JS side. But:
|
Okay, that really is a living hell xD. To better understand, could you explain to me when EDIT: Okay, I think I get it, |
In if(klass === JSConstructor){
// Instances of JSConstructor are transformed into the
// underlying Javascript object
throw new Error('Is it really used ?'); // I added this.
if(pyobj.js_func !== undefined){
return pyobj.js_func
}
return pyobj.js
} Is |
It is used for code like |
Thanks, I pushed a PR #2300 for the work I did on the train. I'll do another PR to fix the server CGI (I also submitted a PR to fix its listening address -with is indeed a security issue-). |
Non, bien vu ! Je l'ai supprimé dans le commit ci-dessus |
Hi,
I'll work on that in the train.
Okay, using prototype substitution is maybe too soon for
list
/tupple
/Array
as their content will not have yet prototype substitution requiring to handle JSObj and PYObj at the same time that will kill a little performances now (as we'll have to handle 2 lists and 2 objects).Here what I suggest for now:
new BrythonAPI(JSTarget, type)
class, wheretype
is the current Python representation of a type, putting a[BrythonAPI]
symbol on the prototype ofJSTarget
. Therefore I won't have to rewrite the whole implementation oflist
ortupple
, I'll make use of the current implementation.toJSWrapper()
, to start delegating responsibilities injsobj2pyobj
, and therefore cleaning it. I'll modifylist
andtupple
class to add a[PYOBJ2JSOBJ]
symbol, to start delegating responsibilities inpyobj2jsobj
, and therefore cleaning it (and making it symmetric). I'll do that for other python types latter.Now handling of
list
/tupple
/Array
, is quite inefficient as lot of copies are made, with can be error prone.What I suggest after thinking:
tupple
: no need for copies during conversions, internal representation should beObject.isFreeze()
.list
: send aProxy
to JS. I know they will performances, but I'm not sure performances on the JS-side matters to us (we shouldn't use it/relies on it if we stick to Brython API). This will enable to convert content when accessed/set by JS (and I think the cost of theProxy
will be mitigated by the conversions). This will enable array synchronisation without trouble, and will prevent to make copies and having different references when using JS API (e.g. storing alist
inside of a JSMap
). Not ideal, once we'll have prototype substitution for all types we will be able to do better.Array
, ifObject.isFreeze()
: convert to atupple
. Else, copy the values and convert to alist
. It would be as if the original object change reference when modified. It isn't true, but JS internals shouldn't be known to us, so it still make sense. Not ideal, once we'll have prototype substitution for all types we will be able to do better.Then if I have time, I may work on Brython
dict
and to think about it (JS <=> Brythonobject
conversion have issues I need to think about).Cordially
The text was updated successfully, but these errors were encountered: