130
Xtext beyond the defaults How to tackle performance problems

Xtext beyond the defaults - how to tackle performance problems

Embed Size (px)

Citation preview

Page 1: Xtext beyond the defaults -  how to tackle performance problems

Xtext beyond the defaults How to tackle performance problems

Page 2: Xtext beyond the defaults -  how to tackle performance problems

Who is that guy?

Page 3: Xtext beyond the defaults -  how to tackle performance problems
Page 4: Xtext beyond the defaults -  how to tackle performance problems
Page 5: Xtext beyond the defaults -  how to tackle performance problems
Page 6: Xtext beyond the defaults -  how to tackle performance problems
Page 7: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Page 8: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Amount of DSLs increases

Page 9: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Amount of DSLs increases

Files get bigger

Page 10: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Amount of DSLs increases

Files get bigger

Amount of files increases

Page 11: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Amount of DSLs increases

Files get bigger

Amount of files increases

Many cross references

Page 12: Xtext beyond the defaults -  how to tackle performance problems

Xtext defaults are a good start!But one size does not fit all!

Amount of DSLs increases

Files get bigger

Amount of files increases

Many cross references

Maybe transitive cross references…

Page 13: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!

Page 14: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

Page 15: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…

Page 16: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…and we can check in broken models…

Page 17: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…and we can check in broken models…

and we generate the missing stuff…

Page 18: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…and we can check in broken models…

and we generate the missing stuff…to make them valid again!

Page 19: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…

We are on Xtext 2.6.2 and can’t update!

and we can check in broken models…and we generate the missing stuff…

to make them valid again!

Page 20: Xtext beyond the defaults -  how to tackle performance problems

Look what we have build!More than 20 DSLs…

and 200.000 lines in one file…

We are on Xtext 2.6.2 and can’t update!

and we can check in broken models…and we generate the missing stuff…

to make them valid again!

Could you please back-port the changes?

Page 21: Xtext beyond the defaults -  how to tackle performance problems

Everything is sooo slow!!! Xtext sucks!!!

Page 22: Xtext beyond the defaults -  how to tackle performance problems

Finally think about improving the situation!

Page 23: Xtext beyond the defaults -  how to tackle performance problems

Update to newest Xtext Version

2.10.x

Page 24: Xtext beyond the defaults -  how to tackle performance problems

Update to newest Xtext Version

2.10.xXte

xt 2.1

1

releas

ed ea

rly 20

17

Page 25: Xtext beyond the defaults -  how to tackle performance problems

Why should I update???

Page 26: Xtext beyond the defaults -  how to tackle performance problems

Because…we killed bugs…

Page 27: Xtext beyond the defaults -  how to tackle performance problems

Because…we killed bugs…

Let wo

rkarou

nds

not la

st for

ever!

Page 28: Xtext beyond the defaults -  how to tackle performance problems

…Speed…

Page 29: Xtext beyond the defaults -  how to tackle performance problems

…Speed…

Resolv

ing cr

oss-

refere

nces h

as

never

been f

aster…

Page 30: Xtext beyond the defaults -  how to tackle performance problems

…new features…

Page 31: Xtext beyond the defaults -  how to tackle performance problems

…new features…

Make

Xtext

work

with o

ther

platfo

rms

Page 32: Xtext beyond the defaults -  how to tackle performance problems

…let’s work together.

Page 33: Xtext beyond the defaults -  how to tackle performance problems

…let’s work together.

It wa

s neve

r easi

er

to con

tribute

!

We are

on G

ithub

:-D

Page 34: Xtext beyond the defaults -  how to tackle performance problems

What about Performance…

Page 35: Xtext beyond the defaults -  how to tackle performance problems

Most problems happen in…

…Index and scoping…

…Memory consumption.

Validations…

… Complex generators…

Page 36: Xtext beyond the defaults -  how to tackle performance problems

I need Xbase in every language…

Page 37: Xtext beyond the defaults -  how to tackle performance problems

I need Xbase in every language…… because my language is

complicated…

Page 38: Xtext beyond the defaults -  how to tackle performance problems

I need Xbase in every language…… because my language is

complicated… … no I can’t explain why…

Page 39: Xtext beyond the defaults -  how to tackle performance problems

I need Xbase in every language…… because my language is

complicated… … no I can’t explain why…

… but there is this small corner case…

Page 40: Xtext beyond the defaults -  how to tackle performance problems

Is a FAST validation really fast…

Page 41: Xtext beyond the defaults -  how to tackle performance problems

Is a FAST validation really fast…… it’s triggered every time I stop typing

Page 42: Xtext beyond the defaults -  how to tackle performance problems

Scoping is sooo complicated…

Page 43: Xtext beyond the defaults -  how to tackle performance problems

Scoping is sooo complicated…… I heard that in nearly every project…

Page 44: Xtext beyond the defaults -  how to tackle performance problems

Scoping is sooo complicated…… I heard that in nearly every project……and people stop improving things when

it work’s for the first time…

Page 45: Xtext beyond the defaults -  how to tackle performance problems

Scoping is sooo complicated…… I heard that in nearly every project……and people stop improving things when

it work’s for the first time…… code is not touched any more because

who knows…

Page 46: Xtext beyond the defaults -  how to tackle performance problems

Scoping is sooo complicated…… I heard that in nearly every project……and people stop improving things when

it work’s for the first time…… code is not touched any more because

who knows…… it worked before you touched it!

Page 47: Xtext beyond the defaults -  how to tackle performance problems

What’s the problem?LocalScope

GlobalScopeImportScopeTypeScope

Caches everywhereThe Index

Lazylinking

EcoreUtils.resolveAll should do the trick!

DerivedState

ContainerState

BatchLinkableResource

Page 48: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Page 49: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Page 50: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Page 51: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Page 52: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher…

Page 53: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher……in a reflective way…

Page 54: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher…

and if grammar changed it might not get called any more……in a reflective way…

Page 55: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher…

and if grammar changed it might not get called any more……in a reflective way…

…BECAUSE IT’S SLOW!

Page 56: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher…

and if grammar changed it might not get called any more……in a reflective way…

…BECAUSE IT’S SLOW!Implement

getScope(EObject context, EReference ref) if(context instanceof Element && ref == MyPackage.Literals.ELEMENT_FEATURE)

up to 10 %

Page 57: Xtext beyond the defaults -  how to tackle performance problems

Scoping APIscope_Element_feature(Element element ,EReference ref)

Called by the PolymorphicDispatcher…

and if grammar changed it might not get called any more……in a reflective way…

…BECAUSE IT’S SLOW!Implement

getScope(EObject context, EReference ref) if(context instanceof Element && ref == MyPackage.Literals.ELEMENT_FEATURE)

up to 10 % Will not

work

with

Xbase

anywa

y…

Page 58: Xtext beyond the defaults -  how to tackle performance problems

Use caches in the ScopeProvider

Page 59: Xtext beyond the defaults -  how to tackle performance problems

Use caches in the ScopeProviderFor each cross reference the ScopeProvider gets asked…

Page 60: Xtext beyond the defaults -  how to tackle performance problems

Use caches in the ScopeProvider

…and it calculates the very same stuff over and over again…

For each cross reference the ScopeProvider gets asked…

Page 61: Xtext beyond the defaults -  how to tackle performance problems

Use caches in the ScopeProvider

…and it calculates the very same stuff over and over again…

For each cross reference the ScopeProvider gets asked…

…cache the calculated stuff and invalidate it when necessary!

Page 62: Xtext beyond the defaults -  how to tackle performance problems

Use caches in the ScopeProvider

…and it calculates the very same stuff over and over again…

For each cross reference the ScopeProvider gets asked…

…cache the calculated stuff and invalidate it when necessary!

The cache of the GlobalScope should be the index and nothing else!

Page 63: Xtext beyond the defaults -  how to tackle performance problems

Use the force of the Index

Page 64: Xtext beyond the defaults -  how to tackle performance problems

Use the force of the IndexHolds all lightweight representations of

referenceable elements and their resources

Page 65: Xtext beyond the defaults -  how to tackle performance problems

Use the force of the IndexHolds all lightweight representations of

referenceable elements and their resources

It’s a HashMap…

It’s super fast since Xtext 2.x and improved further

Page 66: Xtext beyond the defaults -  how to tackle performance problems

Holds all lightweight representations of referenceable elements and their resources

Use the force of the Index

It’s a HashMap…

It’s super fast since Xtext 2.x and improved further

It’s YOUR Index - you can put data in…!

Page 67: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it

Page 68: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it1. Builder picks up DSL files and loads them one by one

Page 69: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it1. Builder picks up DSL files and loads them one by one

2. Creates ResourceDescriptions through ResourceDescriptionManager

Page 70: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it1. Builder picks up DSL files and loads them one by one

2. Creates ResourceDescriptions through ResourceDescriptionManager

3. ResourceDescriptionManager calls ResourceDescriptionsStrategy to create EObjectDescriptions

Page 71: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it1. Builder picks up DSL files and loads them one by one

2. Creates ResourceDescriptions through ResourceDescriptionManager

3. ResourceDescriptionManager calls ResourceDescriptionsStrategy to create EObjectDescriptions

You have to bind a custom impl for the ResourceDescriptionsStrategy in the RuntimeModule

Page 72: Xtext beyond the defaults -  how to tackle performance problems

Index - how to feed it1. Builder picks up DSL files and loads them one by one

2. Creates ResourceDescriptions through ResourceDescriptionManager

3. ResourceDescriptionManager calls ResourceDescriptionsStrategy to create EObjectDescriptions

You have to bind a custom impl for the ResourceDescriptionsStrategy in the RuntimeModule

The default creates a EObjectDescription for EVERY Element that has a name…

Page 73: Xtext beyond the defaults -  how to tackle performance problems

IEObjectDescription create(String simpleName, EObject element, Map<String, String> userData)

Information hiding and userData

Page 74: Xtext beyond the defaults -  how to tackle performance problems

IEObjectDescription create(String simpleName, EObject element, Map<String, String> userData)

Information hiding and userData

Page 75: Xtext beyond the defaults -  how to tackle performance problems

IEObjectDescription create(String simpleName, EObject element, Map<String, String> userData)

Information hiding and userData

Page 76: Xtext beyond the defaults -  how to tackle performance problems

IEObjectDescription create(String simpleName, EObject element, Map<String, String> userData)

Information hiding and userData

Save memory & time

Page 77: Xtext beyond the defaults -  how to tackle performance problems

UserData - what for?

Page 78: Xtext beyond the defaults -  how to tackle performance problems

UserData - what for?Validation

Don’t load the world to get informations - put them in the index

Page 79: Xtext beyond the defaults -  how to tackle performance problems

UserData - what for?Validation

Don’t load the world to get informations - put them in the index

Scoping Don’t resolve proxies for simple informations

Page 80: Xtext beyond the defaults -  how to tackle performance problems

Reference non Xtext models

Page 81: Xtext beyond the defaults -  how to tackle performance problems

Reference non Xtext modelsWe have our own GlobalScopeProvider that does the trick…

Page 82: Xtext beyond the defaults -  how to tackle performance problems

Reference non Xtext modelsWe have our own GlobalScopeProvider that does the trick…

…we load everything and the GlobalScope contains the corresponding EObjectDescriptions…

Page 83: Xtext beyond the defaults -  how to tackle performance problems

Reference non Xtext modelsWe have our own GlobalScopeProvider that does the trick…

…we load everything and the GlobalScope contains the corresponding EObjectDescriptions…

…but it’s slow and we cannot navigate those elements in the editor…

You can do better…

Page 84: Xtext beyond the defaults -  how to tackle performance problems

Reuse the Xtext infrastructure

Page 85: Xtext beyond the defaults -  how to tackle performance problems

Reuse the Xtext infrastructureBind a ResourceServiceProvider…

…so that you can put the elements in the index and make them navigable!

Page 86: Xtext beyond the defaults -  how to tackle performance problems

Reuse the Xtext infrastructureBind a ResourceServiceProvider…

…so that you can put the elements in the index and make them navigable!

GenericResourceServiceProviderUse

It will put everything that has a name in the index…… introduce your own ResourceDescriptionStrategy!

Page 87: Xtext beyond the defaults -  how to tackle performance problems

But the builder picks them up…and it takes ages!

Page 88: Xtext beyond the defaults -  how to tackle performance problems

Put the index in the jar

Page 89: Xtext beyond the defaults -  how to tackle performance problems

Put the index in the jarWhy calculating the index of a static set of files?

Page 90: Xtext beyond the defaults -  how to tackle performance problems

Put the index in the jar

The index is serialisable…

…put it in the jar and load it.

Why calculating the index of a static set of files?

Page 91: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneIt’s sooo slow…

Page 92: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneIt’s sooo slow…

…of course I have my custom Standalone impl…

Page 93: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneResourceSetGlobalScopeProvider

Long time the

was the default.

Page 94: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneResourceSetGlobalScopeProvider

Long time the

was the default.

Today we can do better but you need to use it and know that there is something new…

For Maven- and Gradleplugin it’s done.

Page 95: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneFill the index and install it on the ResourceSet!

Load each resource and ask the ResourceDescriptionManager to create a ResourceDescription…

Page 96: Xtext beyond the defaults -  how to tackle performance problems

Index in StandaloneFill the index and install it on the ResourceSet!

Load each resource and ask the ResourceDescriptionManager to create a ResourceDescription…

Install it on the ResourceSet

Page 97: Xtext beyond the defaults -  how to tackle performance problems

Make big things run again and save your ass!

Up to 80% more faster in 10 minutes!

Page 98: Xtext beyond the defaults -  how to tackle performance problems

CodegeneratorsThey are sooo slow…

Page 99: Xtext beyond the defaults -  how to tackle performance problems

CodegeneratorsThey are sooo slow…

… of course I am using mwe2 to invoke it…

Page 100: Xtext beyond the defaults -  how to tackle performance problems

CodegeneratorsThey are sooo slow…

… of course I am using mwe2 to invoke it…… even in the IDE!

Page 101: Xtext beyond the defaults -  how to tackle performance problems

Incremental generators

Page 102: Xtext beyond the defaults -  how to tackle performance problems

Incremental generatorsThe builder triggers the generator for each resource…

Page 103: Xtext beyond the defaults -  how to tackle performance problems

Incremental generatorsThe builder triggers the generator for each resource…

…when a file changes the builder computes the impact and retriggers the generator for each affected file!

Page 104: Xtext beyond the defaults -  how to tackle performance problems

Incremental generatorsThe builder triggers the generator for each resource…

…when a file changes the builder computes the impact and retriggers the generator for each affected file!

What about m:n scenarios?Solveable with a little effort - but it is worth the work!

Page 105: Xtext beyond the defaults -  how to tackle performance problems

Incremental generatorsThe builder triggers the generator for each resource…

…when a file changes the builder computes the impact and retriggers the generator for each affected file!

What about m:n scenarios?Solveable with a little effort - but it is worth the work!

There is a ParallelBuilderParticipant……you have to bind it for your language…

… make sure all proxies are already resolved!

Page 106: Xtext beyond the defaults -  how to tackle performance problems

Memory consumption

Page 107: Xtext beyond the defaults -  how to tackle performance problems

Memory consumption

DisabledClusteringPolicyDo not unload resource…

Page 108: Xtext beyond the defaults -  how to tackle performance problems

Memory consumption

DisabledClusteringPolicy

DynamicResourceClusteringPolicy

Do not unload resource…

Unload resources when there is no free memory……can be configured.

Page 109: Xtext beyond the defaults -  how to tackle performance problems

The NodeModel is hugeStores the syntax tree with text and positions…

Page 110: Xtext beyond the defaults -  how to tackle performance problems

The NodeModel is hugeStores the syntax tree with text and positions…

…is used to get the position of a specific element or feature…

Page 111: Xtext beyond the defaults -  how to tackle performance problems

The NodeModel is hugeStores the syntax tree with text and positions…

…is used to get the position of a specific element or feature…

…produces a lot of Strings in memory…

Page 112: Xtext beyond the defaults -  how to tackle performance problems

The NodeModel is hugeStores the syntax tree with text and positions…

…is used to get the position of a specific element or feature…

…produces a lot of Strings in memory……and during the builder runs you do not really need

it.

Page 113: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModel

Page 114: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModelThe parser creates it …

Page 115: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModelThe parser creates it …

…it is used to install proxies - so you have to do that differently…

Page 116: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModelThe parser creates it …

…it is used to install proxies - so you have to do that differently…

You want to have it when the editor is used…

Page 117: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModelThe parser creates it …

…it is used to install proxies - so you have to do that differently…

You want to have it when the editor is used…… the load options should be an indicator…

Page 118: Xtext beyond the defaults -  how to tackle performance problems

Switch off the NodeModelThe parser creates it …

…it is used to install proxies - so you have to do that differently…

You want to have it when the editor is used…… the load options should be an indicator…

…what are the implications?

Page 119: Xtext beyond the defaults -  how to tackle performance problems

ImplicationsYou cannot use the NodeModel in validations and

scoping any more…

Page 120: Xtext beyond the defaults -  how to tackle performance problems

ImplicationsYou cannot use the NodeModel in validations and

scoping any more…

…Issues are marked at position 0,0…

…an EditorCallback should revalidate the content.

Page 121: Xtext beyond the defaults -  how to tackle performance problems

ImplicationsYou cannot use the NodeModel in validations and

scoping any more…

…Issues are marked at position 0,0…

…an EditorCallback should revalidate the content.

THIS IS NOT A COMMON THING!

DO IT ONLY WHEN IT IS REALLY NECESSARY!

Page 122: Xtext beyond the defaults -  how to tackle performance problems

Order makes a difference

Page 123: Xtext beyond the defaults -  how to tackle performance problems

Order makes a differenceFiles might belong together…

Page 124: Xtext beyond the defaults -  how to tackle performance problems

Order makes a differenceFiles might belong together…

…and might reference each other.

Page 125: Xtext beyond the defaults -  how to tackle performance problems

Order makes a differenceFiles might belong together…

…and might reference each other.Putting them in an logical order for the builder…

Page 126: Xtext beyond the defaults -  how to tackle performance problems

Order makes a differenceFiles might belong together…

…and might reference each other.Putting them in an logical order for the builder…

… and they do not have be loaded more than once.

Page 127: Xtext beyond the defaults -  how to tackle performance problems

Order makes a differenceFiles might belong together…

…and might reference each other.Putting them in an logical order for the builder…

… and they do not have be loaded more than once.Sometimes it makes sense to not unload them at all.

Page 128: Xtext beyond the defaults -  how to tackle performance problems

Now you know!

Page 129: Xtext beyond the defaults -  how to tackle performance problems

Professional Support

Page 130: Xtext beyond the defaults -  how to tackle performance problems