GNOME Bugzilla – Bug 635371
Reduce overhead of native module support
Last modified: 2010-12-10 16:13:00 UTC
When tracing through the importer code to debug a different problem, I found that for every module import, we would for every element of the search path, create a module object, store a pointer to it in the parent module, try to load the module as a built-in module, fail, remove the pointer in the parent module, and continue. These two patches try to improve the situation.
Created attachment 174924 [details] [review] Don't repeatedly try to load built-in modules There's no point in trying to load a built-in module once per every item in the search path; once is sufficient.
Created attachment 174925 [details] [review] Check for a builtin module before beginning to load it When used to check for builtin modules, import_native_file() would create a module object, set properties on it, store it in the native class, fail to load a builtin module of that name, and then back everything out. Add a pre-check to avoid this. (It means that we do extract the module ID twice when we actually load a built-in module, but built-in modules will a small fraction of modules.)
Review of attachment 174924 [details] [review]: Looks good!
Review of attachment 174925 [details] [review]: ::: gjs/native.c @@ +98,3 @@ + if (gjs_object_get_property(context, module_obj, "__moduleName__", tmp) && + JSVAL_IS_STRING(*tmp)) + return gjs_string_get_ascii(*tmp); This malloc()s now, you'll need to change the signature to char * and adjust callers.
Attachment 174924 [details] pushed as b92ba1b - Don't repeatedly try to load built-in modules