使用自定义dsl的参考序列化大型模型的效果不佳

时间:2019-05-22 11:49:23

标签: performance serialization xtext

  • 使用下面的语法创建一个新的xtext项目
  • 运行测试代码片段以生成文件
  • 请注意保存需要很长时间,如果我将输出更改为xmi,保存起来会很快。

型号

grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"
Model:
    'namespace' name=QualifiedName ';'
    statements+=Statement (statements+=Statement)*
    ;

QualifiedName:
    ID ('.' ID)*;   
Statement:
    (
    SystemThread 
    | FunctionalUseCase
    | Action
);

SystemThread :
    'thread' name=ID
    '{'
        ('functionals' ':' functionals+=[FunctionalUseCase] (',' functionals+=[FunctionalUseCase])* ';')?
        ('actions' ':' qualifyingActions+=[Action|QualifiedName] (',' qualifyingActions+=[Action|QualifiedName])* ';')?  
    '}';

FunctionalUseCase:
    'functional' name=ID
    '{'
        ('actions' ':' prerequisite+=[Action|QualifiedName] (',' prerequisite+=[Action|QualifiedName])* ';')?  
        ('functionals' ':' subfunctionals+=[FunctionalUseCase] (',' subfunctionals+=[FunctionalUseCase])* ';')? 

    '}';
Action :
    'action' name=ID
    '{'


    '}'; 

摘要

public static void createBigModel()
    {
        Injector inj = new MyDslStandaloneSetupGenerated().createInjectorAndDoEMFRegistration();
        String theFile = "C:/data/big3.mydsl"; // if i chnage to xmi it saves quick
        File aFile = new File(theFile);
        if(aFile.exists())
        {
            aFile.delete();
        }
        XtextResourceSet myResourceSet = inj.getInstance(XtextResourceSet.class);
        URI uri = URI.createFileURI(theFile);
        Resource resource = myResourceSet.createResource(uri);

        org.xtext.example.mydsl.myDsl.Model m = MyDslFactory.eINSTANCE.createModel();
        resource.getContents().add(m);
        m.setName("myglobals.foo.bar.test1");

        Action a1 = MyDslFactory.eINSTANCE.createAction();
        a1.setName("a1");
        m.getStatements().add(a1);

        Map<String,FunctionalUseCase> mfuncs = new HashMap<String,FunctionalUseCase>();
        long start = System.currentTimeMillis();

        for(int x=0;x<10000;++x)
        {
            FunctionalUseCase f1 = MyDslFactory.eINSTANCE.createFunctionalUseCase();
            f1.setName("f" + x);
            f1.getPrerequisite().add(a1);
            m.getStatements().add(f1);
            mfuncs.put(f1.getName(), f1);
        }
        for(int x=0;x<10000;++x)
        {
            SystemThread t1 = MyDslFactory.eINSTANCE.createSystemThread();
            t1.setName("thread" + x);
            //String fname = "f"+x;
            //t1.getFunctionals().add(mfuncs.get(fname));
            m.getStatements().add(t1);

        }
        long end1 = System.currentTimeMillis();
        EcoreUtil.resolveAll(resource);
        System.out.println("Creation time = " + (end1-start));
        try
        {
            resource.save(null);    
        }
        catch(Exception e)
        {
            System.out.println(e.getMessage());
        }
        long end2 = System.currentTimeMillis();
        System.out.println("Save time = " + (end2-end1));
    }

0 个答案:

没有答案