Improve performance by precompiling all Python library files#16
Draft
Copilot wants to merge 3 commits into
Draft
Improve performance by precompiling all Python library files#16Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
- Changed wrapmodules.js to precompile ALL .py files instead of just a small ALLOW_LIST - Excluded lib-dynload/ and lib-tk/ directories (contain hyphens causing invalid JS identifiers) - Build time increased from ~23s to ~86s (one-time cost) - stdlib size increased from 1.8MB to 4.6MB (still reasonable) - All modules now load from precompiled JavaScript instead of compiling at runtime - Tests pass: 553/563 (same as before) Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Use path separator in exclusion check to prevent false positives with filenames containing excluded directory names Co-authored-by: acbart <897227+acbart@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize performance of compiling large Python files
Improve performance by precompiling all Python library files
Oct 18, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Compiling large Python files was taking several seconds because the full compilation pipeline (parse → AST → symboltable → compile) ran at runtime for every module import. This caused noticeable delays when importing complex modules like
datetime,difflib, ordataclasses.Solution
This PR eliminates runtime compilation overhead by precompiling all Python library files to JavaScript during the build process. Previously, only 7 modules were precompiled (dataclasses, posixpath, traceback, io, and unittest directories). Now, all ~250 Python standard library modules are precompiled.
Changes
Modified
support/build/wrapmodules.js:lib-dynload/andlib-tk/directories which contain hyphens that cause invalid JavaScript identifiersPerformance Impact
Build Time:
Distribution Size:
Runtime Performance:
Sk.importMain*functions as requested in the issueExample
Testing
Trade-offs
The larger distribution size (4.6MB uncompressed, 807KB gzipped) and longer build time (86s) are acceptable trade-offs for the significant runtime performance improvements. Users benefit immediately without any code changes required.
Fixes #1
Original prompt
Fixes #15
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.