Mass edit/create of Nodes
I've written a language for working with FIX Protoxol and have created plugin for importing XML specifications into MPS Nodes.
Specification is quite big (2.3 Mb of XML code) and creates several thousands Nodes with complex structure.
Initial import is very slow (SAX parser creates Nodes one-by-one) and takes several minutes to complete; MPS hangs for this time. So, my first question:
1) Is it possible to create Progress dialog for Plugin action? Possibly, with Cancel button.
Undo operation works well, but it takes almost the same time to remove all nodes created by plugin. But, if I just select all those nodes in module and delete them from MPS, it takes few seconds. So, built-in delete operation might work in some kind of batch mode with no updating indexes, no typechecks etc.
2) Can we switch model to non-indexed/non-checked mode for batch operations and do all indexes/checks at once after import is done?
I think, this should give significant performance gain.
Please sign in to leave a comment.
I did some performance tests. The code is quite simple:
read action {
- find root node
}
- start outer timer
command {
- start inner timer
- add 10 000 children to root node
- stop inner timer
}
-stop outer timer
Average results are quite impressive:
adding 1000 elements:
time inner: 76 ms.
time outer: 1.5 seconds.
adding 10 000 elements:
time inner: 1 116 ms. (looks like linar time)
time outer: 660 644 ms. (non-linar growth!, 10 minutes of 100% CPU consumption)
My understandig:
Is it possible to create command block that works fast, but does not create Undo log?
It will be used in some rare cases like bath-processing
Hi Alexander,
Did you try to put model in 'loading' mode?
boolean wasLoading = outputModel.setLoading(true);
try {
...
} finally {
outputModel.setLoading(wasLoading);
}
Hello Alexander,
how did you get access to the right place to add nodes? I've the execute(event) -> void method of the action,
whenever I try to get acces to DataContext or Data I get NullPointerException although I defined a "model" action
context parameter.
Is there any other documentation than the User Manual or some samples?
Best regards,
jens
That's amazing!
It took 580 ms to actually modify model and 2ms more to 'commit' the command in loading mode.
Thank you very much!
The code is:
execute outside command: true
action context parameters:
model mdl key: CONTEXT_MODEL required
SModelDescriptor model key: MODEL required
execute(event)->void {
node<Field> node;
read action {
node = this.mdl.roots(Field).findFirst({~it => it.fixId == 0; });
System.out.println(node);
}
boolean wasLoading = this.model.getSModel().setLoading(true);
command {
node.enumItems.remove all;
}
long nanoTime = System.currentTimeMillis();
command {
long nanoTime2 = System.currentTimeMillis();
for (int k = 0; k < 100; k++) {
for (int i = 0; i < 100; i++) {
node<EnumItem> iter = this.mdl.new node(EnumItem , <no prototype>);
node.enumItems.add(iter);
}
}
long delta2 = System.currentTimeMillis() - nanoTime2;
info "time inner: " + delta2 + "ms. " ;
}
this.model.getSModel().setLoading(wasLoading);
long delta = System.currentTimeMillis() - nanoTime;
info "time outer: " + delta + "ms. " ;
}
Works superb, thanks Alexander!
Is there something like an easy to use file select dialog or have I to use Swing to choose a file to import?
Best regards
jens
No, I still try to apply UI language for that, but with not much success.
My current problem is how to convert Dialog (described with UI language) into real JComponent / JDialog.
Jens,
DataContext is not the right way to get some data. Action context parameters is a more-DSL way to get the data you need.
About NPE - could you provide the code which causes it?
To find examples of actions:
1) go to ActionDeclaration concept
2) find instance of this concept
All actions in MPS are written in Plugin language, so there are hundreds of examples ;-)
Hi Mihail,
thanks for your reply. In the meantime I've tried out the code Alexander postet at
05.11.2009 14:19 - it works fine. My next goal is - if I have some spare time - a next little
sample at http://github.com/mpsamples showing generation and re-reading of files.
Best regards
jens
So, finally I did it: on http://github.com/mpSamples/mps.samples.plugin you'll find a basic sample with no frills, just showing how to create a plugin, choose a file, read it and modify the model root node.
Comments highly welcome!
Best regards
jens