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
including source maps, to allow for debugging python with in-browser debugger #123
Comments
A better solution might be an optional debugger toolbar that you could attach to and pull out of a web page but right now that's a pipe dream IMO. |
@JamesHutchison Do you mean that Brython would implement its own parallel debugging toolchain? All my browsers already have an optional debugger toolbar built into the browser itself :). |
yeah, like the console but with debugging functionality. Kind of like the django debug toolbar. |
@JamesHutchison This would be much, much worse than just supporting source maps. It would be years of work and a huge ongoing maintenance burden to maintain a parallel debugging and instrumentation infrastructure. Browsers have increasingly sophisticated tooling and Brython should just leverage it. |
Source maps aren't actually an option. For one, they only work on pre-compiled javascript files (you can't use .html files that contain python or any dynamically generated code for example). Two, you're still debugging javascript, thus you would at best know where you are at in python. It would still take a lot of effort to investigate values or step through code. Three, I hate the debuggers in browsers. |
You can use source maps on dynamically generated code (at least with firefox) by setting a URL: http://blog.getfirebug.com/2009/08/11/give-your-eval-a-name-with-sourceurl/ - the docs for it look pretty thin though so I might be misinterpreting. I'm not saying that browser debuggers are necessarily the best ever, but there are operations like "set a breakpoint" which would be next to impossible from within Brython itself if it isn't completely rewritten to support that, but the browser debugger gives you "for free". You're right that there are other issues, like sanely representing Python's variable scope from within the JS debugger's view. |
Aah, here's something a bit more authoritative: http://stackoverflow.com/questions/14375567/getting-source-maps-working-with-evaluated-code |
I'm not denying that a debug toolbar would be a lot of effort. That's why I said it was a pipe dream :) |
@JamesHutchison - I suppose I might have overstated the case a bit. I actually think a "debug toolbar" project would be a super useful thing - there are lots of Brython-specific things one might want to debug; for example, visualizing |
OTOH, On 4 February 2015 at 04:09, Glyph notifications@github.com wrote:
|
@jsbueno - Frame objects aren't the problem. The way that a debugger works involves interacting with the runtime, and brython still relies heavily on the browser runtime (it does not, and probably can not, have its own bytecode and instruction format). On native platforms you can work around this by simply using multiple threads and suspending some of them, but in the browser you only have the main event loop and "workers" which can't draw any UI. |
Being able to analyze the state of the python environment when a you have an uncaught exception would be nice. But yes, I don't really see it being possible to pause/step/resume execution unless Brython is re-written to use a state machine with byte code. Which might end up being molasses slow. |
I should probably not under-emphasize the "optimization" aspect of this. Loading my pretty basic fork of Deferred takes on the order of 5 seconds of CPU time on a fairly fast, modern computer; most of that seems to be spent translating the Python to JavaScript. Being able to do this ahead of time and cache it would be really great. Perhaps Brython could even do this automatically using LocalStorage, looking at caching headers and only re-requesting Python source if it's changed, just like real Python does automatically with PYC files? (Being able to do it truly ahead of time is still useful for production websites that want the first visit to be snappy, of course.) |
On the performance side of things I think this is closely related to #117 . |
The thing is, when you import a module it is stored as a bunch of objects, which when converted to json takes up a lot of space. On top of that you have to remove the circular references and then re-build them again. The optimal solution for .py files seems to be to leave them as-is and just use #117 so the most common ones aren't a daisy chain of ajax calls. |
I don't think I understand this comment. In other Python runtimes, In other words, optimizing only the compilation time, not the import time. Optimizing import time could then be further accomplished by simply concatenating the |
I think I get you. When I looked into this earlier I was focusing on saving the actual module object that gets created when you do an import, but if I understand what you're saying, you mean changing this:
into something like this:
That might provide some useful savings, especially for the re module. |
Yeah, something like that. I'm actually thinking something more like:
so that things like While it would definitely help with the |
Sounds like we need to extend the VFS functionality:
|
For the first suggestion, I have found out that compiled code is between 5x-10x larger than the python version. The parser/compiler is very fast, so the download time might take longer than the time it takes to parse and compile the python code. for the third suggestion, I have been working on a brython_loader.js file, which can be used to dynamically load brython_dict.js OR brython.js (and possibily py_VFS) OR all the py_*.js file (and possibly py_VFS). This could be expanded by providing extra loader options. |
You could minify and gzip the compiled code for better results. Likely it compresses very well :).
This has not been my experience; on localhost, where the transfer is instant, it still takes me about 5s to load a page with 16 or so modules on it, which is 300ms per module. That is not a very fast compiler :-). Plus, you pay the execution cost of the transpiler on every page-load, but you only pay the download cost of cached files once. |
I agree with glyph. Bill does the code in node_bridge.js work for you? When I try it, I get this:
So far the only way I have been able to get compiling of js to work is to inject javascript in selenium on a running browser instance. |
@JamesHutchison - Have you tried PhantomJS? If you want the environment of a running browser instance but the convenience of a command-line tool it's nice. |
It has been 6 months or so since I've worked on node_bridge.js. It is On Fri, Feb 13, 2015 at 2:21 PM, Glyph notifications@github.com wrote:
|
On Thu, Feb 12, 2015 at 10:23 PM, Glyph notifications@github.com wrote:
|
Are you taking into account that the execution time of the module includes the transpiler time of submodules? I did some testing and of the ~2.2 seconds it took to import the
|
@JamesHutchison - My measurement has not been terribly scientific, but this is completely consistent with my subjective experience of loading progressively larger numbers of small modules and watching things get slower without loading an appreciable amount more data. |
I've been trying to debug #121 and it has been very challenging to do so because it's not possible to get a JavaScript debugger to set a breakpoint in a Python file.
If you could easily do ahead-of-time compilation (emitting, let's say,
.pyc.js
files next to the.py
files), it would at least be possible to set breakpoints in the generated JavaScript source. Even better, with pre-generated source files we could potentially have source maps which would facilitate actually debugging Python code with a JavaScript debugger.Is this already possible? I searched the documentation, but maybe I'm just not looking for the right string.
The text was updated successfully, but these errors were encountered: