SlideShare a Scribd company logo
Made available under EPL 1.0
Deterministic Lazy Mutable
OCL Collections
Edward Willink
Willink Transformations Ltd
Eclipse Foundation
MMT Component co-Lead
OCL Project Lead
QVTd Project Lead
QVTo Committer
OMG (Model Driven Solutions)
OCL 2.3, 2.4, 2.5 RTF Chair
QVT 1.2, 1.3, 1.4 RTF Chair
OCL 2017 @ STAF 2017
20th July 2017
20-July-2017 Deterministic Lazy OCL Collections 2Made available under EPL 1.0
Overview
Collection performance
New Collection implementation
bypass/reconsider specification obstacles
unify Bag, OrderedSet, Sequence, Set
fewer conversions
deterministic - predictable, debuggable
Sequence - same size/speed
Set - 13% larger, faster/slower
lazy - usually smaller, slower
lazy+partial - usually smaller, faster
mutable/cached - quadratic => linear, smaller, faster
20-July-2017 Deterministic Lazy OCL Collections 3Made available under EPL 1.0
Specification obstacles
is OCL deterministic?
no partial Collection evaluation
no Collection mutation
many Collection kinds
20-July-2017 Deterministic Lazy OCL Collections 4Made available under EPL 1.0
Traditional Collection Value Classes
Distinct Bag/OrderedSet/Sequence/Set classes
20-July-2017 Deterministic Lazy OCL Collections 5Made available under EPL 1.0
Traditional Collection Implementation
Delegate from OCL to Java semantics
20-July-2017 Deterministic Lazy OCL Collections 6Made available under EPL 1.0
New Collection Implementation
Single OCL class
Bag/OrderedSet
/Sequence/Set
'Two' Java collections
ArrayList<T>
deterministic iteration
HashMap<T,Integer>
unique-element
=> repeat count
One lazy loading Iterator
Many accessing Iterators
20-July-2017 Deterministic Lazy OCL Collections 7Made available under EPL 1.0
Size
list map new vs old
Sequence ordered elements null no change
Set ordered unique elements unique element => 1 13% larger
OrderedSet ordered unique elements unique element => 1 13% larger
Bag ordered unique elements unique element => count 13% larger
64 bit machine
list element pointer - 8 bytes
set/map node + pointers - 60 bytes
map + list - 68 bytes => +13%
?? custom combined implementation ??
20-July-2017 Deterministic Lazy OCL Collections 8Made available under EPL 1.0
Bag-aware iteration
OrderedSet, Sequence, Set
list iterator returns each element once
Bag
default iterator returns each collection element once
multiple returns for repeated content
bag iterator returns each distinct element once
single return for each repeated content
repeat count accessible from iterator
faster bag-aware impementation
20-July-2017 Deterministic Lazy OCL Collections 9Made available under EPL 1.0
Creation Speed
2 collections to create rather than 1
'new' about 2 times slower
20-July-2017 Deterministic Lazy OCL Collections 10Made available under EPL 1.0
Iteration Speed
simple list rather than sparse tree iteration
'new' 3 times faster for large sets
iteration faster than creation
more than 3 iterations needed to outweigh creation
20-July-2017 Deterministic Lazy OCL Collections 11Made available under EPL 1.0
Determinism as specified
Non-determinism is bad
Is OCL deterministic?
11.7.1: Collection::asSequence() : Sequence(T)
A Sequence that contains all the elements from self, in an order dependent on
the particular concrete collection type.
11.7.2: Set::asSequence() : Sequence(T)
A Sequence that contains all the elements from self, in undefined order.
Ditto asOrderedSet().
11.9.1 Collection::any
... an indeterminate choice of one of them is returned ...
(non-normative) A.2.5.5 Note that the semantics of the operation asSequence
is nondeterministic.
normative: asSequence unknown, determinate
non-normative: asSequence non-determinate
overall: unclear
20-July-2017 Deterministic Lazy OCL Collections 12Made available under EPL 1.0
Implemented Determinism
OCL Set implemented by Java HashSet
asSequence computed by Java iterator
iteration order determined by hash codes
hash code determined by object location
location dependent on garbage collection timing
Convenient implementation is non-determinate
OCL is therefore non-determinate
OCL-based applications non-determinate
M2M transformations non-determinate
hard to justify, hard to debug
20-July-2017 Deterministic Lazy OCL Collections 13Made available under EPL 1.0
NewCollection Determinism
Every Collection has a deterministic list
Collection::any can be respecified as the first choice
13% non-Sequence Collection size penalty
swings/roundabouts speed gain/penalty
acceptable cost for a very fundamental fix
new mitigating opportunities...
20-July-2017 Deterministic Lazy OCL Collections 14Made available under EPL 1.0
Specified Eagerness, Invalidity
specification exposition implies full evaluation
one operation/iteration after another
specification mandates full evaluation
any invalid collection element => invalid result
requires full evaluation to check for not-invalid
a->including(b)->excludes(c)
get: a
compute: a+b
check: a+b excludes c
invalidity => full eager evaluation
20-July-2017 Deterministic Lazy OCL Collections 15Made available under EPL 1.0
What is invalid?
null - a well-defined undefined value
invalid - every other bad
null navigation
divide by zero
Sequence/OrderedSet index out of bounds
4-level logic to accommodate invalid
mayBeNull = null or mayBeNull.doSomething()
null = null or null .doSomething()
true or invalid
true
20-July-2017 Deterministic Lazy OCL Collections 16Made available under EPL 1.0
Are Program Failures invalid?
OCL Specification is silent about
Stack Overflow
Network Connection Failure
etc.
presumably program failure is invalid
Normal OCL usage
program failures are fatal, result cannot be useful
program failure as invalid is perverse, inefficient
failure may be 'caught' and so succeed
OCL-specified Debugger / Job control
job failure must be useable in a computation
20-July-2017 Deterministic Lazy OCL Collections 17Made available under EPL 1.0
Program Failure Clarification
clarify: Let program failures always be 'strict'
cannot be 'caught' by and/or
pedantically now 5-level logic
can only be caught by oclIsFailure()
supports the obscure Job control use case
invalid sources are enumerable
many expressions are provably not-invalid
redundant computations can be skipped
lazy/partial evaluation can be valid and profitable
20-July-2017 Deterministic Lazy OCL Collections 18Made available under EPL 1.0
Eager Collection Evaluation
a->including(b)->including(c)
1: load and cache a
2: load and cache b
3: compute ab, 4: cache ab
5: load and cache c
6: compute abc, 7: cache abc
1
2
3 4
5
6 7 8
20-July-2017 Deterministic Lazy OCL Collections 19Made available under EPL 1.0
Lazy Collection Evaluation
a->including(b)->including(c)
1: load and cache b
2: load and cache c
3.1: request an abc element
4.1: request an ab+c element
5.1: request an ab element
6:.1 request an a+b element
7.1: request an a element
8.1: request an a element
1 2
345678
20-July-2017 Deterministic Lazy OCL Collections 20Made available under EPL 1.0
Multi-access Lazy Evaluation
Cache to avoid repeated lazy
first lazy computation populates the cache
further computations re-use the cache
20-July-2017 Deterministic Lazy OCL Collections 21Made available under EPL 1.0
NewCollection modes
lazy Bag, OrderedSet, Sequence, Set
iterator, list, map
eager/lazily cached Sequence
iterator, list, map
eager/lazily cached Bag, OrderedSet, Set
iterator, list, map
lazy/eager/lazily cached Collection Operation
e.g. IncludingIteration extends NewCollectionValue
overridden loading iterator performs the algorithm
Gotcha - lazy/cached must be determined early
awkward as part of a casual API
'easy' using automated compile-time analysis
20-July-2017 Deterministic Lazy OCL Collections 22Made available under EPL 1.0
Full Eager/Lazy Performance
a->including(b)->including(c)
lazy has fewer caches to create
eager has fewer function calls
20-July-2017 Deterministic Lazy OCL Collections 23Made available under EPL 1.0
Immutable repeated computation
aCollection->iterate(e; acc : Set(String) |
acc->including(e.name))
eager: each iteration executes including() once
new collection created for each iteration
0.5 * N * N element assigns - bad O(N*N) speed
O(N*N) intermediate elements - bad O(N*N) size
lazy: each iteration daisy chains 2 iterators
final lazy result
2 * N * N iterator next() calls - bad O(N*N) speed
2 * N small iterators - good O(N) size
20-July-2017 Deterministic Lazy OCL Collections 24Made available under EPL 1.0
Mutable repeated computation
OCL side-effect free - no Collection mutation
Set::including(element) rather than Set::add(element)
but specification is on observable behavior
unobserved behavior can perform mutation
Compile-time expression analysis, rewrite
acc is only accessed by including()
aCollection->iterate(e; acc : Set(String) |
acc->mutableIncluding(e.name))
mutable: each iteration updates collection
N element assigns - good O(N) speed
N element result - good O(N) size
20-July-2017 Deterministic Lazy OCL Collections 25Made available under EPL 1.0
Mutable Accumulation Performance
aCollection->iterate(e; acc : Coll(String) | acc->including(e.name))
clear benefit for modest/large collection
possible degration for small collections 'in the noise'
exploits a compile time analysis
20-July-2017 Deterministic Lazy OCL Collections 26Made available under EPL 1.0
select() idioms
sourceCollection->select(booleanPredicate)
type conformance
OCL 2.0: S->select(oclIsKindOf(MyType)).oclAsType(MyType)
OCL 2.4: S->selectByKind(MyType)
amenable to global compile-time analysis
appropriate caching, similar to allInstances
lookup
S->select(element | element.name = wantedName)
full search for each lookup - O(N)
applications often have many lookups - O(N*N)
introduce a value2key cache - O(N)
20-July-2017 Deterministic Lazy OCL Collections 27Made available under EPL 1.0
select() lookup performance
let S = Sequence{1..N} in
let t = S->collect(i|Tuple{x=i}) in
S->collect(i | t->select(x = i))
Compile-time analysis to balance trade-offs
possible for QVT, less obvious for OCL
huge speed benefit iff there are many lookups
significant cache cost, perhaps 8 times
20-July-2017 Deterministic Lazy OCL Collections 28Made available under EPL 1.0
Status
Oct 2016: ... Martin's lightning presentation
Nov 2016: Initial Eclipse OCL experiments
major API compatibility difficulty: next major version
Apr 2017: Results, workshop submission
May 2017: Eclipse OCL integration
API compatibility resolved by a level of wrappers
Gotcha, lazy operation calls get wrong parameters
need lazy operation call / let variable
June 2017: Context 'iterator'
Today: only available on ewillink/509670 branch
20-July-2017 Deterministic Lazy OCL Collections 29Made available under EPL 1.0
Summary
Deterministic OCL is feasible (and ? required)
13% non-Sequence Collection memory cost
Partial collection evaluation is feasible
but only if program failures are not invalid
Lazy collection evaluation is challenging
huge memory saving, marginal slow down
lazy variable access must use correct state
Mutable collection evaluation very beneficial
linear rather than quadratic speed/size cost
Partial+Lazy+Mutable+Deterministic
mutual speed-ups
shared compile-time analysis

More Related Content

ODP
OCL 2.4. (... 2.5)
ODP
Safe navigation in OCL
PPT
Lp seminar
PDF
Python to scala
PPT
jimmy hacking (at) Microsoft
PPTX
Jug Marche: Meeting June 2014. Java 8 hands on
PDF
Kotlin Receiver Types 介紹
PDF
RxJS - The Reactive Extensions for JavaScript
OCL 2.4. (... 2.5)
Safe navigation in OCL
Lp seminar
Python to scala
jimmy hacking (at) Microsoft
Jug Marche: Meeting June 2014. Java 8 hands on
Kotlin Receiver Types 介紹
RxJS - The Reactive Extensions for JavaScript

What's hot (19)

PDF
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
PDF
Seattle useR Group - R + Scala
PDF
Wrapping java in awesomeness aka condensator
PDF
Computational Techniques for the Statistical Analysis of Big Data in R
PPTX
Vlsi lab2
PPTX
Intro to Akka Streams
PDF
Functional Reactive Programming in Clojurescript
PDF
MongoDB World 2016: Implementing Async Networking in MongoDB 3.2
PDF
Parallel streams in java 8
PDF
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
PDF
Cilk - An Efficient Multithreaded Runtime System
PDF
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
PPTX
Sync with async
PPT
Calico docker+ipam
PDF
Harnessing the Power of Java 8 Streams
PDF
Mikio Braun – Data flow vs. procedural programming
PDF
CLaSH HIW 2014
PPTX
Sharding and Load Balancing in Scala - Twitter's Finagle
PPTX
Scilab: Computing Tool For Engineers
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Seattle useR Group - R + Scala
Wrapping java in awesomeness aka condensator
Computational Techniques for the Statistical Analysis of Big Data in R
Vlsi lab2
Intro to Akka Streams
Functional Reactive Programming in Clojurescript
MongoDB World 2016: Implementing Async Networking in MongoDB 3.2
Parallel streams in java 8
Flink Forward SF 2017: Joe Olson - Using Flink and Queryable State to Buffer ...
Cilk - An Efficient Multithreaded Runtime System
Instrumenting Go (Gopherconindia Lightning talk by Bhasker Kode)
Sync with async
Calico docker+ipam
Harnessing the Power of Java 8 Streams
Mikio Braun – Data flow vs. procedural programming
CLaSH HIW 2014
Sharding and Load Balancing in Scala - Twitter's Finagle
Scilab: Computing Tool For Engineers
Ad

Similar to Deterministic Lazy Mutable OCL Collections (20)

PDF
Enriching your models with OCL
ODP
The OCLforUML Profile
PDF
An OCL Map Type
PPT
OclApunteNavegacion.ppt
PPTX
OCL in EMF
PDF
Enriching Your Models with OCL
ODP
OCL 2.5 plans
ODP
Modeling the OCL Standard Library
PDF
java unit 4 pdf - about java collections
PPTX
JAVA(UNIT 4)
PPTX
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
ODP
Aligning OCL and UML
PPTX
FP vs OOP : Design Methodology by Harshad Nawathe
PPT
Java collection
DOCX
Collection frame work
PPT
PDF
Java Collection Framework
PPTX
Collection Framework-1.pptx
PDF
Collections Framework Begineers guide 2
PDF
Collections Framework Beginners Guide 2
Enriching your models with OCL
The OCLforUML Profile
An OCL Map Type
OclApunteNavegacion.ppt
OCL in EMF
Enriching Your Models with OCL
OCL 2.5 plans
Modeling the OCL Standard Library
java unit 4 pdf - about java collections
JAVA(UNIT 4)
22CS305-UNIT-1.pptx ADVANCE JAVA PROGRAMMING
Aligning OCL and UML
FP vs OOP : Design Methodology by Harshad Nawathe
Java collection
Collection frame work
Java Collection Framework
Collection Framework-1.pptx
Collections Framework Begineers guide 2
Collections Framework Beginners Guide 2
Ad

More from Edward Willink (20)

PDF
OCL Visualization A Reality Check
PDF
OCL 2019 Keynote Retrospective and Prospective
ODP
A text model - Use your favourite M2M for M2T
ODP
Shadow Objects
ODP
Commutative Short Circuit Operators
ODP
The Micromapping Model of Computation
ODP
Optimized declarative transformation First Eclipse QVTc results
ODP
Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...
ODP
The Importance of Opposites
ODP
OCL Specification Status
ODP
At Last an OCL Debugger
ODP
QVT Traceability: What does it really mean?
ODP
Embedded OCL Integration and Debugging
ODP
OCL Integration and Code Generation
ODP
Yet Another Three QVT Languages
ODP
OCL - The Bigger Picture
PPT
UMLX and QVT and ATL
PPT
Model Transformation A Personal Perspective
ODP
Fast, Faster and Super-Fast Queries
ODP
Eclipse OCL Summary
OCL Visualization A Reality Check
OCL 2019 Keynote Retrospective and Prospective
A text model - Use your favourite M2M for M2T
Shadow Objects
Commutative Short Circuit Operators
The Micromapping Model of Computation
Optimized declarative transformation First Eclipse QVTc results
Local Optimizations in Eclipse QVTc and QVTr using the Micro-Mapping Model of...
The Importance of Opposites
OCL Specification Status
At Last an OCL Debugger
QVT Traceability: What does it really mean?
Embedded OCL Integration and Debugging
OCL Integration and Code Generation
Yet Another Three QVT Languages
OCL - The Bigger Picture
UMLX and QVT and ATL
Model Transformation A Personal Perspective
Fast, Faster and Super-Fast Queries
Eclipse OCL Summary

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Hybrid model detection and classification of lung cancer
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
project resource management chapter-09.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
A Presentation on Artificial Intelligence
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Getting Started with Data Integration: FME Form 101
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Encapsulation_ Review paper, used for researhc scholars
DP Operators-handbook-extract for the Mautical Institute
OMC Textile Division Presentation 2021.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
1. Introduction to Computer Programming.pptx
Hindi spoken digit analysis for native and non-native speakers
Hybrid model detection and classification of lung cancer
Enhancing emotion recognition model for a student engagement use case through...
Zenith AI: Advanced Artificial Intelligence
project resource management chapter-09.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Heart disease approach using modified random forest and particle swarm optimi...
A Presentation on Artificial Intelligence
NewMind AI Weekly Chronicles - August'25-Week II
Univ-Connecticut-ChatGPT-Presentaion.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
Getting Started with Data Integration: FME Form 101

Deterministic Lazy Mutable OCL Collections

  • 1. Made available under EPL 1.0 Deterministic Lazy Mutable OCL Collections Edward Willink Willink Transformations Ltd Eclipse Foundation MMT Component co-Lead OCL Project Lead QVTd Project Lead QVTo Committer OMG (Model Driven Solutions) OCL 2.3, 2.4, 2.5 RTF Chair QVT 1.2, 1.3, 1.4 RTF Chair OCL 2017 @ STAF 2017 20th July 2017
  • 2. 20-July-2017 Deterministic Lazy OCL Collections 2Made available under EPL 1.0 Overview Collection performance New Collection implementation bypass/reconsider specification obstacles unify Bag, OrderedSet, Sequence, Set fewer conversions deterministic - predictable, debuggable Sequence - same size/speed Set - 13% larger, faster/slower lazy - usually smaller, slower lazy+partial - usually smaller, faster mutable/cached - quadratic => linear, smaller, faster
  • 3. 20-July-2017 Deterministic Lazy OCL Collections 3Made available under EPL 1.0 Specification obstacles is OCL deterministic? no partial Collection evaluation no Collection mutation many Collection kinds
  • 4. 20-July-2017 Deterministic Lazy OCL Collections 4Made available under EPL 1.0 Traditional Collection Value Classes Distinct Bag/OrderedSet/Sequence/Set classes
  • 5. 20-July-2017 Deterministic Lazy OCL Collections 5Made available under EPL 1.0 Traditional Collection Implementation Delegate from OCL to Java semantics
  • 6. 20-July-2017 Deterministic Lazy OCL Collections 6Made available under EPL 1.0 New Collection Implementation Single OCL class Bag/OrderedSet /Sequence/Set 'Two' Java collections ArrayList<T> deterministic iteration HashMap<T,Integer> unique-element => repeat count One lazy loading Iterator Many accessing Iterators
  • 7. 20-July-2017 Deterministic Lazy OCL Collections 7Made available under EPL 1.0 Size list map new vs old Sequence ordered elements null no change Set ordered unique elements unique element => 1 13% larger OrderedSet ordered unique elements unique element => 1 13% larger Bag ordered unique elements unique element => count 13% larger 64 bit machine list element pointer - 8 bytes set/map node + pointers - 60 bytes map + list - 68 bytes => +13% ?? custom combined implementation ??
  • 8. 20-July-2017 Deterministic Lazy OCL Collections 8Made available under EPL 1.0 Bag-aware iteration OrderedSet, Sequence, Set list iterator returns each element once Bag default iterator returns each collection element once multiple returns for repeated content bag iterator returns each distinct element once single return for each repeated content repeat count accessible from iterator faster bag-aware impementation
  • 9. 20-July-2017 Deterministic Lazy OCL Collections 9Made available under EPL 1.0 Creation Speed 2 collections to create rather than 1 'new' about 2 times slower
  • 10. 20-July-2017 Deterministic Lazy OCL Collections 10Made available under EPL 1.0 Iteration Speed simple list rather than sparse tree iteration 'new' 3 times faster for large sets iteration faster than creation more than 3 iterations needed to outweigh creation
  • 11. 20-July-2017 Deterministic Lazy OCL Collections 11Made available under EPL 1.0 Determinism as specified Non-determinism is bad Is OCL deterministic? 11.7.1: Collection::asSequence() : Sequence(T) A Sequence that contains all the elements from self, in an order dependent on the particular concrete collection type. 11.7.2: Set::asSequence() : Sequence(T) A Sequence that contains all the elements from self, in undefined order. Ditto asOrderedSet(). 11.9.1 Collection::any ... an indeterminate choice of one of them is returned ... (non-normative) A.2.5.5 Note that the semantics of the operation asSequence is nondeterministic. normative: asSequence unknown, determinate non-normative: asSequence non-determinate overall: unclear
  • 12. 20-July-2017 Deterministic Lazy OCL Collections 12Made available under EPL 1.0 Implemented Determinism OCL Set implemented by Java HashSet asSequence computed by Java iterator iteration order determined by hash codes hash code determined by object location location dependent on garbage collection timing Convenient implementation is non-determinate OCL is therefore non-determinate OCL-based applications non-determinate M2M transformations non-determinate hard to justify, hard to debug
  • 13. 20-July-2017 Deterministic Lazy OCL Collections 13Made available under EPL 1.0 NewCollection Determinism Every Collection has a deterministic list Collection::any can be respecified as the first choice 13% non-Sequence Collection size penalty swings/roundabouts speed gain/penalty acceptable cost for a very fundamental fix new mitigating opportunities...
  • 14. 20-July-2017 Deterministic Lazy OCL Collections 14Made available under EPL 1.0 Specified Eagerness, Invalidity specification exposition implies full evaluation one operation/iteration after another specification mandates full evaluation any invalid collection element => invalid result requires full evaluation to check for not-invalid a->including(b)->excludes(c) get: a compute: a+b check: a+b excludes c invalidity => full eager evaluation
  • 15. 20-July-2017 Deterministic Lazy OCL Collections 15Made available under EPL 1.0 What is invalid? null - a well-defined undefined value invalid - every other bad null navigation divide by zero Sequence/OrderedSet index out of bounds 4-level logic to accommodate invalid mayBeNull = null or mayBeNull.doSomething() null = null or null .doSomething() true or invalid true
  • 16. 20-July-2017 Deterministic Lazy OCL Collections 16Made available under EPL 1.0 Are Program Failures invalid? OCL Specification is silent about Stack Overflow Network Connection Failure etc. presumably program failure is invalid Normal OCL usage program failures are fatal, result cannot be useful program failure as invalid is perverse, inefficient failure may be 'caught' and so succeed OCL-specified Debugger / Job control job failure must be useable in a computation
  • 17. 20-July-2017 Deterministic Lazy OCL Collections 17Made available under EPL 1.0 Program Failure Clarification clarify: Let program failures always be 'strict' cannot be 'caught' by and/or pedantically now 5-level logic can only be caught by oclIsFailure() supports the obscure Job control use case invalid sources are enumerable many expressions are provably not-invalid redundant computations can be skipped lazy/partial evaluation can be valid and profitable
  • 18. 20-July-2017 Deterministic Lazy OCL Collections 18Made available under EPL 1.0 Eager Collection Evaluation a->including(b)->including(c) 1: load and cache a 2: load and cache b 3: compute ab, 4: cache ab 5: load and cache c 6: compute abc, 7: cache abc 1 2 3 4 5 6 7 8
  • 19. 20-July-2017 Deterministic Lazy OCL Collections 19Made available under EPL 1.0 Lazy Collection Evaluation a->including(b)->including(c) 1: load and cache b 2: load and cache c 3.1: request an abc element 4.1: request an ab+c element 5.1: request an ab element 6:.1 request an a+b element 7.1: request an a element 8.1: request an a element 1 2 345678
  • 20. 20-July-2017 Deterministic Lazy OCL Collections 20Made available under EPL 1.0 Multi-access Lazy Evaluation Cache to avoid repeated lazy first lazy computation populates the cache further computations re-use the cache
  • 21. 20-July-2017 Deterministic Lazy OCL Collections 21Made available under EPL 1.0 NewCollection modes lazy Bag, OrderedSet, Sequence, Set iterator, list, map eager/lazily cached Sequence iterator, list, map eager/lazily cached Bag, OrderedSet, Set iterator, list, map lazy/eager/lazily cached Collection Operation e.g. IncludingIteration extends NewCollectionValue overridden loading iterator performs the algorithm Gotcha - lazy/cached must be determined early awkward as part of a casual API 'easy' using automated compile-time analysis
  • 22. 20-July-2017 Deterministic Lazy OCL Collections 22Made available under EPL 1.0 Full Eager/Lazy Performance a->including(b)->including(c) lazy has fewer caches to create eager has fewer function calls
  • 23. 20-July-2017 Deterministic Lazy OCL Collections 23Made available under EPL 1.0 Immutable repeated computation aCollection->iterate(e; acc : Set(String) | acc->including(e.name)) eager: each iteration executes including() once new collection created for each iteration 0.5 * N * N element assigns - bad O(N*N) speed O(N*N) intermediate elements - bad O(N*N) size lazy: each iteration daisy chains 2 iterators final lazy result 2 * N * N iterator next() calls - bad O(N*N) speed 2 * N small iterators - good O(N) size
  • 24. 20-July-2017 Deterministic Lazy OCL Collections 24Made available under EPL 1.0 Mutable repeated computation OCL side-effect free - no Collection mutation Set::including(element) rather than Set::add(element) but specification is on observable behavior unobserved behavior can perform mutation Compile-time expression analysis, rewrite acc is only accessed by including() aCollection->iterate(e; acc : Set(String) | acc->mutableIncluding(e.name)) mutable: each iteration updates collection N element assigns - good O(N) speed N element result - good O(N) size
  • 25. 20-July-2017 Deterministic Lazy OCL Collections 25Made available under EPL 1.0 Mutable Accumulation Performance aCollection->iterate(e; acc : Coll(String) | acc->including(e.name)) clear benefit for modest/large collection possible degration for small collections 'in the noise' exploits a compile time analysis
  • 26. 20-July-2017 Deterministic Lazy OCL Collections 26Made available under EPL 1.0 select() idioms sourceCollection->select(booleanPredicate) type conformance OCL 2.0: S->select(oclIsKindOf(MyType)).oclAsType(MyType) OCL 2.4: S->selectByKind(MyType) amenable to global compile-time analysis appropriate caching, similar to allInstances lookup S->select(element | element.name = wantedName) full search for each lookup - O(N) applications often have many lookups - O(N*N) introduce a value2key cache - O(N)
  • 27. 20-July-2017 Deterministic Lazy OCL Collections 27Made available under EPL 1.0 select() lookup performance let S = Sequence{1..N} in let t = S->collect(i|Tuple{x=i}) in S->collect(i | t->select(x = i)) Compile-time analysis to balance trade-offs possible for QVT, less obvious for OCL huge speed benefit iff there are many lookups significant cache cost, perhaps 8 times
  • 28. 20-July-2017 Deterministic Lazy OCL Collections 28Made available under EPL 1.0 Status Oct 2016: ... Martin's lightning presentation Nov 2016: Initial Eclipse OCL experiments major API compatibility difficulty: next major version Apr 2017: Results, workshop submission May 2017: Eclipse OCL integration API compatibility resolved by a level of wrappers Gotcha, lazy operation calls get wrong parameters need lazy operation call / let variable June 2017: Context 'iterator' Today: only available on ewillink/509670 branch
  • 29. 20-July-2017 Deterministic Lazy OCL Collections 29Made available under EPL 1.0 Summary Deterministic OCL is feasible (and ? required) 13% non-Sequence Collection memory cost Partial collection evaluation is feasible but only if program failures are not invalid Lazy collection evaluation is challenging huge memory saving, marginal slow down lazy variable access must use correct state Mutable collection evaluation very beneficial linear rather than quadratic speed/size cost Partial+Lazy+Mutable+Deterministic mutual speed-ups shared compile-time analysis