From 98d7002d1dca4b62042e1589fd5b9b3805d57f7a Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sun, 20 Dec 2015 13:22:19 +0000 Subject: event/utils/methodpool: Add a cache of compiled code objects With the addition of function line number handling, the overhead of the compile functions is no longer negligible. We tend to compile the same pieces of code over and over again so wrapping a cache around this is beneficial and removes the overhead of line numbered functions. Life cycle of a cache using a global like this is in theory problematic although in reality unlikely to be an issue. It can be dealt with if/as/when we deal with the other global caches. Signed-off-by: Richard Purdie --- lib/bb/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/bb/utils.py') diff --git a/lib/bb/utils.py b/lib/bb/utils.py index e564bb6ff..cd5fcede3 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -298,10 +298,15 @@ def better_compile(text, file, realfile, mode = "exec", lineno = None): will print the offending lines. """ try: + cache = bb.methodpool.compile_cache(text) + if cache: + return cache code = compile(text, realfile, mode, ast.PyCF_ONLY_AST) if lineno is not None: ast.increment_lineno(code, lineno) - return compile(code, realfile, mode) + code = compile(code, realfile, mode) + bb.methodpool.compile_cache_add(text, code) + return code except Exception as e: error = [] # split the text into lines again -- cgit 1.2.3-korg