Skip to content
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

Goldilocks brython.js #117

Closed
ghost opened this issue Jan 25, 2015 · 5 comments
Closed

Goldilocks brython.js #117

ghost opened this issue Jan 25, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented Jan 25, 2015

The current brython.js is too small. I have to load a bunch of files almost all the time.
brython_dist.js or brython.js + VFS is too big. I don't need every single library!
But goldilocks... is just right.

This suggestion is to change the brython.js build to be like VFS except it will use these files:

goldilocks_files = {'browser/__init__.py', 'browser/local_storage.py', 'browser/object_storage.py', 'browser/session_storage.py',
    'sys.py', 'javascript.js', '_browser.js', '_ajax.js', '_html.js', '_random.js', '_sys.js', '_timer.js', 'builtins.js', 'pickle.py',
    'json.js', 'browser/html.py', 'locale.py', 'datetime.py', 'math.js', 'modulefinder.js', 'time.js', 'browser/timer.py'}

And change the look-up logic so that it checks for included libs, and then checks the staticlibs.

i.e.

    if($B.use_VFS){
        funcs = [import_from_VFS]
    }else if($B.static_stdlib_import){
        funcs = [import_from_VFS, import_from_stdlib_static]
    }else{
        funcs = [import_from_VFS, import_from_stdlib]
    }

The import_from_VFS function is quite cheap, so I don't see any point in not doing it.

The idea is that these are the files that people will probably use or the site uses. Any other files will be imported normally.

I've already half-way written the code, just need some input/confirmation before I put the effort into polishing it and making a merge request.

Extra file size ends up only being 94kb

@kikocorreoso
Copy link
Member

+1

Sometimes I have thought in creating something like http://www.highcharts.com/download so a user can choose what they need. I need to find the way to see how to manage the recurrent imports of libs online.

@ghost
Copy link
Author

ghost commented Jan 30, 2015

any other feedback on this? Pierre?

@ghost
Copy link

ghost commented Feb 3, 2015

we definitely need to look for ways to decrease the file sizes.

A few months ago, I moved the unittest package (and modules unittests) to a py_unittests.js file which is similar to VFS. Most users are not going to use these on a site, so why include them in VFS? I think we should do the same for other modules and see what makes sense to include.

@ghost
Copy link
Author

ghost commented Feb 12, 2015

As mentioned in issue #123, we could refactor the VFS functionality to support multiple files - this could be "common.json" for example

PierreQuentel added a commit that referenced this issue Feb 26, 2015
… , "browser.html" and "javascript". Related to issue #117
@PierreQuentel
Copy link
Contributor

In the commit referenced above I have introduced a new script, builtin_modules.js, which is included in brython.js. It makes the modules "browser", "browser.html" and "javascript" available without having to fetch and run the source code.

Technically, they are inserted in the object __BRYTHON__.imported ; there is no need to modifiy the VFS functionality.

As a consequence, the modules local_storage, session_storage, and object_storage are not loaded with the module "browser", so the names LocalStorage, SessionStorage and ObjectStorage are not defined as attributes of the browser module, and neither is WebSocket. To use local storage and web sockets, the syntax will be the one that is documented, ie

from browser import local_storage

I don't think it's a major issue : in fact I was not comfortable with the fact that there were 2 ways to interact with local storage, one with the code above and another with from browser import LocalStorage

This change doesn't cover all that was suggested in this issue, but it can be a starting point to reduce the loading time of frequently used modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants