extremeheat / JSPyBridge

🌉. Bridge to interoperate Node.js and Python
MIT License
694 stars 53 forks source link

Calling function with large string parameter blocks forever #70

Open James4Ever0 opened 1 year ago

James4Ever0 commented 1 year ago

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.

mara004 commented 11 months ago

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.