Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: Source/bindings/scripts/blink_idl_lexer.py

Issue 183013013: Pre-cache PLY lex table and use optimized mode (5% build time improvement) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix order Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/generated_bindings.gyp ('k') | Source/bindings/scripts/blink_idl_parser.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/blink_idl_lexer.py
diff --git a/Source/bindings/scripts/blink_idl_lexer.py b/Source/bindings/scripts/blink_idl_lexer.py
index 2af8f81b42eb70bf4150d6ddd0f76f20daa2294f..ba9c969c4bc2b6c4c438863db98d26fe19c9b73c 100644
--- a/Source/bindings/scripts/blink_idl_lexer.py
+++ b/Source/bindings/scripts/blink_idl_lexer.py
@@ -54,11 +54,16 @@ PLY:
import os.path
import sys
-# Base lexer is in Chromium src/tools/idl_parser
+# PLY is in Chromium src/third_party/ply
module_path, module_name = os.path.split(__file__)
-tools_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pardir, os.pardir, 'tools')
-sys.path.append(tools_dir)
+third_party = os.path.join(module_path, os.pardir, os.pardir, os.pardir, os.pardir)
+# Insert at front to override system libraries, and after path[0] == script dir
+sys.path.insert(1, third_party)
+from ply import lex
+# Base lexer is in Chromium src/tools/idl_parser
+tools_dir = os.path.join(third_party, os.pardir, 'tools')
+sys.path.append(tools_dir)
from idl_parser.idl_lexer import IDLLexer
REMOVE_TOKENS = ['COMMENT']
@@ -80,11 +85,40 @@ class BlinkIDLLexer(IDLLexer):
for token in tokens:
self._RemoveToken(token)
- def __init__(self):
+ def __init__(self, debug=False, optimize=True, outputdir=None):
+ if debug:
+ # Turn off optimization and caching to help debugging
+ optimize = False
+ outputdir = None
+ if outputdir:
+ # Need outputdir in path because lex imports the cached lex table
+ # as a Python module
+ sys.path.append(outputdir)
+
IDLLexer.__init__(self)
+ # Overrides to parent class
self._RemoveTokens(REMOVE_TOKENS)
+ # Optimized mode substantially decreases startup time (by disabling
+ # error checking), and also allows use of Python's optimized mode.
+ # See: Optimized Mode
+ # http://www.dabeaz.com/ply/ply.html#ply_nn15
+ self._lexobj = lex.lex(object=self,
+ debug=debug,
+ optimize=optimize,
+ outputdir=outputdir)
+
+
+################################################################################
+
+def main(argv):
+ # If file itself executed, build and cache lex table
+ try:
+ outputdir = argv[1]
+ except IndexError as err:
+ print 'Usage: %s OUTPUT_DIR' % argv[0]
+ return 1
+ lexer = BlinkIDLLexer(outputdir=outputdir)
-# If run by itself, attempt to build the lexer
if __name__ == '__main__':
- lexer = BlinkIDLLexer()
+ sys.exit(main(sys.argv))
« no previous file with comments | « Source/bindings/generated_bindings.gyp ('k') | Source/bindings/scripts/blink_idl_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698