JSPyBridge icon indicating copy to clipboard operation
JSPyBridge copied to clipboard

Calling function with large string parameter blocks forever

Open James4Ever0 opened this issue 3 years ago • 1 comments

To demonstrate this problem, the following code is used:

# saying you have a large html file called "target.html"
from javascript import require
JSDOM = require("jsdom").JSDOM
filepath = "target.html"

with open(filepath,"r") as f:
    html = f.read()
    dom = JSDOM(html) # the step taking forever
    print("dom loaded?", dom)

I can only get this working by writing this in javascript and read the file in the js script, only return the final result to python.

James4Ever0 avatar Dec 10 '22 14:12 James4Ever0

I believe is for the same reason as https://github.com/extremeheat/JSPyBridge/issues/67#issuecomment-1618083903 / https://github.com/extremeheat/JSPyBridge/pull/103#issuecomment-1765155766, just with the opposite direction. JSON serialization isn't suitable to transfer big binary data.

PR https://github.com/extremeheat/JSPyBridge/pull/103 proposes a new transfer strategy that would fix the Js -> Py direction. Something similar will be needed for Py -> Js. And I suppose pythonia will be affected as well and equally require a bidirectional fix.

However, note that it will still be more performant to produce data natively in the language where it's needed and avoid transferring big values if you can help it, for even though the transfer can be made much more efficient, it will always add some overhead. This is because Js/Py are separate processes that do not share the same memory, but have to communicate over a pipe instead.

mara004 avatar Nov 19 '23 14:11 mara004