-
Notifications
You must be signed in to change notification settings - Fork 83
Faster doSaveModule
#2833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
sungshik
wants to merge
3
commits into
performance-improvements-main
Choose a base branch
from
performance-improvements/faster-dosavemodule
base: performance-improvements-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+32
−16
Draft
Faster doSaveModule
#2833
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -421,16 +421,20 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, | |
| if(isEmpty(component)) return ms; | ||
|
|
||
| //println("doSaveModule: <component>, <m_imports>, <m_extends>, <moduleScopes>"); | ||
| component_scopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MODID mid <- component }; | ||
| set[MODID] componentScopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MODID mid <- component }; | ||
| map[str, MODID] componentScopesByUri = (); | ||
| set[MODID] filteredModuleScopes = {}; | ||
| map[str, MODID] filteredModuleScopesByUri = (); | ||
| loc2moduleName = invertUnique(ms.moduleLocs); | ||
|
|
||
| bool isContainedInComponentScopes(loc inner, map[loc,loc] m){ | ||
| return any(cs <- component_scopes, isContainedIn(inner, cs, m)); | ||
| inner = m[inner] ? inner; | ||
| return inner.uri in componentScopesByUri && isContainedIn(inner, componentScopesByUri[inner.uri]); | ||
| }; | ||
|
|
||
| bool isContainedInFilteredModuleScopes(loc inner, map[loc,loc] m){ | ||
| return any(cs <- filteredModuleScopes, isContainedIn(inner, cs, m)); | ||
| inner = m[inner] ? inner; | ||
| return inner.uri in filteredModuleScopesByUri && isContainedIn(inner, filteredModuleScopesByUri[inner.uri]); | ||
| }; | ||
|
|
||
| for(currentModule <- component){ | ||
|
|
@@ -443,25 +447,36 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, | |
|
|
||
| bom = makeBom(currentModule, ms); | ||
|
|
||
| // Lookup fields only once to save interpreter time (significant) | ||
| paths = tm.paths; | ||
| facts = tm.facts; | ||
| specializedFacts = tm.specializedFacts; | ||
| useDef = tm.useDef; | ||
| logical2physical = tm.logical2physical; | ||
| definitions = tm.definitions; | ||
|
|
||
| componentScopesByUri = (s.uri: s | loc s <- componentScopes, loc s := logical2physical[s] ? s); | ||
|
|
||
| extendedModuleScopes = {m | MODID m <- extends, hasProperty(m, ms, checked())}; | ||
| extendedModuleScopes += {*tm.paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules | ||
| extendedModuleScopes += {*paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules | ||
| filteredModuleScopes = {m | MODID m <- (currentModule + imports), hasProperty(m, ms, checked())} + extendedModuleScopes; | ||
| filteredModuleScopesByUri = (m.uri: m | loc m <- filteredModuleScopes, loc m := logical2physical[m] ? m); | ||
|
|
||
| TModel m1 = tmodel(); | ||
| m1.version = getCurrentTplVersion(); | ||
| m1.rascalTplVersion = compilerConfig.rascalTplVersion; | ||
| m1.modelName = moduleId2moduleName(currentModule); | ||
| m1.moduleLocs = (m1.modelName : currentModule); | ||
|
|
||
| m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInFilteredModuleScopes(key, tm.logical2physical)); | ||
| m1.facts = (key : facts[key] | key <- facts, isContainedInFilteredModuleScopes(key, logical2physical)); | ||
|
|
||
| m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key, tm.logical2physical), any(fms <- filteredModuleScopes, isContainedIn(key, fms))); | ||
| m1.specializedFacts = (key : specializedFacts[key] | key <- specializedFacts, isContainedInComponentScopes(key, logical2physical), isContainedInFilteredModuleScopes(key, logical2physical)); | ||
| m1.facts += m1.specializedFacts; | ||
|
|
||
| m1.messages = [msg | msg <- tm.messages, isContainedIn(msg.at, currentModule, tm.logical2physical)]; | ||
| m1.messages = [msg | msg <- tm.messages, isContainedIn(msg.at, currentModule, logical2physical)]; | ||
| ms.messages[currentModule] = toSet(m1.messages); | ||
|
|
||
| filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes}; | ||
| // filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes}; | ||
| m1.scopes = tm.scopes; | ||
| // m1.scopes | ||
| // = ( inner : tm.scopes[inner] | ||
|
|
@@ -480,23 +495,23 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, | |
| m1.store[key_common_keyword_fields] | ||
| = tm.store[key_common_keyword_fields] ? []; | ||
|
|
||
| m1.paths = { tup | tuple[MODID from, PathRole pathRole, MODID to] tup <- tm.paths, tup.from == currentModule || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ }; | ||
| m1.paths = { tup | tuple[MODID from, PathRole pathRole, MODID to] tup <- paths, tup.from == currentModule || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ }; | ||
|
|
||
| keepRoles = variableRoles + keepInTModelRoles; | ||
| m1.useDef = { <u, d> | ||
| | <u, d> <- tm.useDef, | ||
| isContainedIn(u, currentModule, tm.logical2physical) | ||
| || (tm.definitions[d]? && tm.definitions[d].idRole in keepRoles) | ||
| | <u, d> <- useDef, | ||
| isContainedIn(u, currentModule, logical2physical) | ||
| || (definitions[d]? && definitions[d].idRole in keepRoles) | ||
| }; | ||
|
|
||
| // Filter model for current module and replace functions in defType by their defined type | ||
|
|
||
| defs = for(tup:<loc _scope, str _id, str _orgId, IdRole idRole, loc defined, DefInfo _defInfo> <- tm.defines){ | ||
| if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined, tm.logical2physical) | ||
| if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined, logical2physical) | ||
| ) | ||
| : ( idRole in keepInTModelRoles | ||
| && ( isContainedInComponentScopes(defined, tm.logical2physical) | ||
| || isContainedInFilteredModuleScopes(defined, tm.logical2physical) | ||
| && ( isContainedInComponentScopes(defined, logical2physical) | ||
| || isContainedInFilteredModuleScopes(defined, logical2physical) | ||
| ) | ||
| ) | ||
| ) | ||
|
|
@@ -509,11 +524,12 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, | |
|
|
||
| m1.definitions = ( def.defined : def | Define def <- m1.defines); // TODO this is derived info, can we derive it later? | ||
| // Remove default expressions and fragments | ||
| // (Relatively expensive: can take >50% of the execution time of this function) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this comment here as a reminder that this piece of code might be, or not, amenable to further optimization. |
||
| m1 = visit(m1) { | ||
| case kwField(AType atype, str fieldName, str definingModule, Expression _defaultExp) => kwField(atype, fieldName, definingModule) | ||
| case loc l : if(!isEmpty(l.fragment)) insert l[fragment=""]; | ||
| }; | ||
| m1.logical2physical = tm.logical2physical; | ||
| m1.logical2physical = logical2physical; | ||
| ms = deleteProperty(currentModule, ms, tpl_saved()); | ||
| ms = addTModel(currentModule, m1, ms); | ||
| // println("TModel for <currentModule>:"); iprintln(m1); | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable
filteredModuleScopePathsis unused. I am keeping it as a comment, instead of removing it, because there are other commented lines in this function that use that variable.