diff options
author | Simon Sapin <simon.sapin@exyr.org> | 2019-09-27 06:37:54 +0200 |
---|---|---|
committer | Simon Sapin <simon.sapin@exyr.org> | 2019-09-27 13:53:19 +0200 |
commit | 5c60023cb8ad6f07927bd53f30c90873d07b300f (patch) | |
tree | 9ea739dbeb622a918b7636558f7ed81ff6f4bb49 /components/script/dom/bindings/codegen/BindingGen.py | |
parent | 049527872e6dfadf3f69f0f9fa6fffee520a6f7b (diff) | |
download | servo-5c60023cb8ad6f07927bd53f30c90873d07b300f.tar.gz servo-5c60023cb8ad6f07927bd53f30c90873d07b300f.zip |
WebIDL codegen: Replace cmake with a single Python script
When playing around with Cargo’s new timing visualization:
https://internals.rust-lang.org/t/exploring-crate-graph-build-times-with-cargo-build-ztimings/10975/21
… I was surprised to see the `script` crate’s build script take 76 seconds.
I did not expect WebIDL bindings generation to be *that* computationally
intensive.
It turns out almost all of this time is overhead. The build script uses CMake
to generate bindings for each WebIDL file in parallel, but that causes a lot
of work to be repeated 366 times:
* Starting up a Python VM
* Importing (parts of) the Python standard library
* Importing ~16k lines of our Python code
* Recompiling the latter to bytecode, since we used `python -B` to disable
writing `.pyc` file
* Deserializing with `cPickle` and recreating in memory the results
of parsing all WebIDL files
----
This commit remove the use of CMake and cPickle for the `script` crate.
Instead, all WebIDL bindings generation is done sequentially
in a single Python process. This takes 2 to 3 seconds.
Diffstat (limited to 'components/script/dom/bindings/codegen/BindingGen.py')
-rw-r--r-- | components/script/dom/bindings/codegen/BindingGen.py | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/components/script/dom/bindings/codegen/BindingGen.py b/components/script/dom/bindings/codegen/BindingGen.py deleted file mode 100644 index 63cc68e46e5..00000000000 --- a/components/script/dom/bindings/codegen/BindingGen.py +++ /dev/null @@ -1,54 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at https://mozilla.org/MPL/2.0/. - -import sys -import os -sys.path.append(os.path.join(".", "parser")) -sys.path.append(os.path.join(".", "ply")) -import cPickle -from Configuration import Configuration -from CodegenRust import CGBindingRoot, replaceFileIfChanged - - -def generate_binding_rs(config, outputprefix, webidlfile): - """ - |config| Is the configuration object. - |outputprefix| is a prefix to use for the header guards and filename. - """ - - filename = outputprefix + ".rs" - module = CGBindingRoot(config, outputprefix, webidlfile).define() - if not module: - print "Skipping empty module: %s" % (filename) - elif replaceFileIfChanged(filename, module): - print "Generating binding implementation: %s" % (filename) - - -def main(): - # Parse arguments. - from optparse import OptionParser - usagestring = "usage: %prog configFile outputdir outputPrefix webIDLFile" - o = OptionParser(usage=usagestring) - (options, args) = o.parse_args() - - if len(args) != 4: - o.error(usagestring) - configFile = os.path.normpath(args[0]) - outputdir = args[1] - outputPrefix = args[2] - webIDLFile = os.path.normpath(args[3]) - - # Load the parsing results - resultsPath = os.path.join(outputdir, 'ParserResults.pkl') - with open(resultsPath, 'rb') as f: - parserData = cPickle.load(f) - - # Create the configuration data. - config = Configuration(configFile, parserData) - - # Generate the prototype classes. - generate_binding_rs(config, outputPrefix, webIDLFile) - -if __name__ == '__main__': - main() |