Browse Source

Some minor performance tweaks

Yentl Van Tendeloo 8 years ago
parent
commit
74498d6d91
3 changed files with 30 additions and 3 deletions
  1. 10 0
      bootstrap/core_algorithm.alc
  2. 5 2
      bootstrap/transform.alc
  3. 15 1
      kernel/modelverse_jit/intrinsics.py

+ 10 - 0
bootstrap/core_algorithm.alc

@@ -15,10 +15,15 @@ Element core = ?
 
 String core_model_location = "models/core"
 
+Element caches = ?
+
 Void function initialize_core():
 	// TODO make this more flexible by putting it in the bootstrap in a similar way as other models
 	add_code_model(import_node("models/ActionLanguage"), "models/Conformance_MV", wrap_conformance)
 
+	dict_add_fast(caches, "models", dict_create())
+	dict_add_fast(caches, "users", dict_create())
+
 	return !
 
 Element function get_instanceOf_links(model_id : String, metamodel_id : String):
@@ -186,10 +191,15 @@ String function get_model_id(name : String):
 	Element models
 	String model
 
+	if (dict_in(caches["models"], name)):
+		if (value_eq(read_attribute(core, caches["models"][name], "name"), name)):
+			return caches["models"][name]!
+
 	models = allInstances(core, "Model")
 	while (set_len(models) > 0):
 		model = set_pop(models)
 		if (value_eq(name, read_attribute(core, model, "name"))):
+			dict_overwrite(caches["models"], name, model)
 			return model!
 	
 	return ""!

+ 5 - 2
bootstrap/transform.alc

@@ -17,12 +17,14 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 	String next
 	Element tmp
 	String elem_id
+	Element scheduled
 
 	Element reverse
 	reverse = make_reverse_dictionary(schedule_model["model"])
 
 	// Initialize
 	schedule = list_create()
+	scheduled = set_create()
 	workset = set_create()
 	all_elements = allAssociationDestinations(schedule_model, LHS, "LHS_contains")
 	full_all_elements = set_copy(all_elements)
@@ -34,7 +36,7 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 		// workset is empty, but we still need to add to the list
 		// Therefore, we pick a random, unbound node, and add it to the workset
 		new_element = set_pop(all_elements)
-		while (bool_or(list_in(schedule, new_element), is_edge(schedule_model["model"][new_element]))):
+		while (bool_or(set_in(scheduled, new_element), is_edge(schedule_model["model"][new_element]))):
 			// Element is not usable, so pick another one
 			new_element = set_pop(all_elements)
 		set_add(workset, new_element)
@@ -45,10 +47,11 @@ Element function make_matching_schedule(schedule_model : Element, LHS : String,
 			next = set_pop(workset)
 
 			// Check if element might not be already used somewhere
-			if (bool_not(list_in(schedule, next))):
+			if (bool_not(set_in(scheduled, next))):
 				if (set_in(full_all_elements, next)):
 					if (bool_not(set_in(ignore, read_attribute(schedule_model, next, "label")))):
 						list_insert(schedule, next, 0)
+						set_add(scheduled, next)
 					else:
 						required_size = required_size - 1
 						continue!

+ 15 - 1
kernel/modelverse_jit/intrinsics.py

@@ -463,9 +463,23 @@ MISC_CFG_INTRINSICS = {
     'dict_in_node' : __dict_in_node_cfg,
 
     'set_in' : __dict_in_cfg,
+    'set_len' : __read_nr_out_cfg,
 
     # List operations
-    'list_len' : __read_nr_out_cfg
+    'list_len' : __read_nr_out_cfg,
+
+    'list_create' :
+        lambda original_def:
+        original_def.redefine(
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Literal(None)))),
+    'set_create' :
+        lambda original_def:
+        original_def.redefine(
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Literal(None)))),
+    'dict_create' :
+        lambda original_def:
+        original_def.redefine(
+            cfg_ir.CreateNode(original_def.insert_before(cfg_ir.Literal(None)))),
 }
 
 def register_time_intrinsic(target_jit):