SlideShare a Scribd company logo
1 of 33
Download to read offline
© 2016– Andrei Alexandrescu. Do not redistribute. 1 / 33
Opening Keynote
Prepared for DConf 2016
Andrei Alexandrescu, Ph.D.
2016-05-04
© 2016– Andrei Alexandrescu. Do not redistribute. 2 / 33
Welcome to DConf
2016!
Sup
© 2016– Andrei Alexandrescu. Do not redistribute. 3 / 33
First Five Minutes
© 2016– Andrei Alexandrescu. Do not redistribute. 5 / 33
• First five minutes become the next five years
• Out of the box experience
◦ Website
◦ Tutorials
◦ Documentation
◦ Libraries
• (Self-)Curating dub
Scaling Up
© 2016– Andrei Alexandrescu. Do not redistribute. 6 / 33
• Many thanks for a great year!
◦ Thanks for being here!
◦ The Foundation is up!
• Roles: build czar, sysadmin, webmaster, social
media, conference organizer. . .
• Enhance the “point of contact” approach
• Please get me fired!
• I’m in charge of too many things
Raising the Bar on Contributions
© 2016– Andrei Alexandrescu. Do not redistribute. 7 / 33
• The weird thing about “okay work”
• Reasons to NOT pull something:
◦ “Porque no?”
◦ Respected contributor
◦ “That’s a lot of work”
◦ One-liners and many-liners
◦ Renames
◦ Refactorings showing no clear
improvement
• Churn, illusion of progress
Raising the Bar on Contributions
© 2016– Andrei Alexandrescu. Do not redistribute. 8 / 33
• Reasons to pull something:
◦ Adds value
◦ Refactors for a net benefit
◦ Fixes a bug “positively”
◦ Makes code simpler
◦ Makes code faster
◦ Automates
◦ Improves documentation
• talent × time = win
Resource Management
© 2016– Andrei Alexandrescu. Do not redistribute. 9 / 33
Take the Garbage Out
© 2016– Andrei Alexandrescu. Do not redistribute. 10 / 33
Commit to making D
great with and without
a GC
Issues with RC
© 2016– Andrei Alexandrescu. Do not redistribute. 11 / 33
• Overall: RC a qualified success story in
computing
• Make it work with immutable
• Make it safe
• Make it work with classes and value types
• Make it work lazily (COW)
◦ Copies should not have arbitrary cost
Basics
© 2016– Andrei Alexandrescu. Do not redistribute. 12 / 33
• The C++ way: library smart pointers
+ Apply to any type
− Apply to any type (unsafe)
− Needs mutable
• Envisioned:
◦ In-language support + library hooks
◦ Attribute @rc
◦ opIncRef(uint), opDecRef(uint)
Safety
© 2016– Andrei Alexandrescu. Do not redistribute. 13 / 33
• Main issue: unaccounted refs
struct RC { int a; ... }
void fun(ref RC obj, ref int x) {
obj = RC();
... use x ...
}
void gun() {
RC obj = ...;
fun(obj, obj.f);
}
• Variant: obj is global
• Attack: Insert extra incs/decs for ref params
• Fuse successive incs/decs where possible
• Elide increments where possible
immutable
© 2016– Andrei Alexandrescu. Do not redistribute. 14 / 33
• Apparent contradiction!
◦ immutable: “I’ll never change, honey”
◦ RC: surreptitious change in metadata
• We considered revoking immutable rights for
RC objects
• If only we had a means to:
◦ allocate metadata along with each object
◦ type metadata independently
◦ access metadata in O(1). . .
© 2016– Andrei Alexandrescu. Do not redistribute. 15 / 33
“Why do you completely discard
external reference counting
approach (i.e. storing refcount in
GC/allocator internal data
structures bound to allocated
memory blocks)?”
– Dicebot
© 2016– Andrei Alexandrescu. Do not redistribute. 16 / 33
“Never ascribe to malice that
which is adequately explained by
incompetence.”
– Robert J. Hanlon
AffixAllocator!. . . AffixAllocator!. . .
© 2016– Andrei Alexandrescu. Do not redistribute. 17 / 33
• Part of std.experimental.allocator from
day one
• AffixAllocator!(GCAllocator, uint):
◦ fronts each allocation with an extra uint
◦ . . . that’s independently typed
◦ Accessible in O(1)!
• Use this allocator for creating RC objects
import bigo;
© 2016– Andrei Alexandrescu. Do not redistribute. 18 / 33
“Big O” Notation
© 2016– Andrei Alexandrescu. Do not redistribute. 19 / 33
• Compact characterization of algorithms
• Growing importance in recent years
• Usually confined to documentation
• Pen and paper suffices for non-generic code
• Better: make it generic and a discoverable
part of the API
Scaling Naming Conventions
© 2016– Andrei Alexandrescu. Do not redistribute. 20 / 33
• Nomenclature approaches don’t scale
• removeLinTime, removeLogTime,
removeConstTime
• Hierarchy of speeds: faster functions
subsume slower ones
• Sometimes O(·) depends on 2+ parameters
• Helpless with HOFs
• Doesn’t scale to large APIs
• We want to automate this
Related Work
© 2016– Andrei Alexandrescu. Do not redistribute. 21 / 33
• Java: initially complexity-oblivious APIs
◦ Later: RandomAccess “marker” interface
• STL carefully specifies complexity
◦ Archetypal examples: push_front,
push_back, operator[]
◦ Syntax complexity follows algo complexity
◦ Undecided on “best effort” vs. “present or
not”, e.g. distance
Loosely Related Work
© 2016– Andrei Alexandrescu. Do not redistribute. 22 / 33
• O(·) analysis part of typechecking (Marion
2011)
• Automated Higher-Order Complexity Analysis
(Benzinger 2004)
• Monotonic State (Pilkiewicz et al 2011)
Here
© 2016– Andrei Alexandrescu. Do not redistribute. 23 / 33
• User:
◦ Introduces annotations
◦ Defines composition
• Framework:
◦ Provides algebra
◦ Propagates attributes
◦ Calculates composition
• Notably for higher-order functions
◦ Makes result available by static
introspection
Synopsis
© 2016– Andrei Alexandrescu. Do not redistribute. 24 / 33
// Generic doubly-linked list of E
struct DoublyLinkedList(E) {
...
// Complexity is O(1)
void insertFront(E x) @O(1);
}
// Generic contiguous array of E
struct Array(E) {
...
// Complexity is O(n) in the first argument (this)
void insertFront(E x) @O("n");
}
Synopsis
© 2016– Andrei Alexandrescu. Do not redistribute. 25 / 33
// Complexity of insertFrontMany is the complexity of
// C.insertFront multiplied by the size of the second
// argument.
void insertFrontMany(C, E)(ref C container, E[] items)
@(complexity!(C.insertFront) * O("n2")) {
foreach (item; items) {
c.insertFront(item);
}
}
Introspection
© 2016– Andrei Alexandrescu. Do not redistribute. 26 / 33
static assert(
complexity!(insertFrontMany!MyC) <=
O("n2") * log(O("n1")),
"Too high complexity for insertFrontMany.");
Conventions
© 2016– Andrei Alexandrescu. Do not redistribute. 27 / 33
• Unannotated functions are considered O(1)
• "nk" for the kth parameter
• this is the first parameter
• "n" if only one parameter of interest
Algebra
© 2016– Andrei Alexandrescu. Do not redistribute. 28 / 33
• Credit: Timon Gehr
C O
i j
v
pij
ij loglij
vij
• pij, lij positive, pij + lij > 0
• log n, n, n log n,
√
n1 + n2 log n2, n2 log n1 . . .
Normal Form & Partial Order
© 2016– Andrei Alexandrescu. Do not redistribute. 29 / 33
• Normal form for terms: most compact form
• A ≤ A′
immediate (compare vars and powers)
• T ≤ T′
iff for each atom A in T there’s an
atom A′
in T′
with A ≤ A′
• C ≤ C′
iff for each term T in C there’s a term
T′
in C′
with T ≤ T′
• Normal form for complexities: no terms are
ordered by ≤
Operations on Complexities
© 2016– Andrei Alexandrescu. Do not redistribute. 30 / 33
• Comparison for equality and ≤
• Addition (add, then normalize)
• Multiplication (multiply, then normalize)
• Normalization keeps only the fastest-growing
terms: O (n +
√
m + m log n) + O m2
+ log n
is O n + m2
+ m log n
• log just a bit trickier (can’t express
log(n1 + n2))
log for Complexities
© 2016– Andrei Alexandrescu. Do not redistribute. 31 / 33
• Rely on a simple approximation
log
i j
v
pij
ij loglij
vij
i j,pij>0
log vij (1)
• log log very slow growing, ignore
• log(a + b) ≤ log(ab)
Implementation
© 2016– Andrei Alexandrescu. Do not redistribute. 32 / 33
• Operator overloading (==, <=, +, *)
• Pivotal use of compile-time evaluation
◦ Perfect match with attribute expressions
• Run-time computation automatically available
• Sweet spot between convenience and
complexity (sic)
• Coming soon!
© 2016– Andrei Alexandrescu. Do not redistribute. 33 / 33
One Last Thing

More Related Content

Similar to DConf 2016 Opening Keynote (12)

Avogadro 2 and Open Chemistry
Avogadro 2 and Open ChemistryAvogadro 2 and Open Chemistry
Avogadro 2 and Open Chemistry
 
12735 cse539 at2 hw
12735 cse539 at2 hw12735 cse539 at2 hw
12735 cse539 at2 hw
 
Resonance Introduction at SacPy
Resonance Introduction at SacPyResonance Introduction at SacPy
Resonance Introduction at SacPy
 
Parallel Optimization in Machine Learning
Parallel Optimization in Machine LearningParallel Optimization in Machine Learning
Parallel Optimization in Machine Learning
 
Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014Solvcon PyCon APAC 2014
Solvcon PyCon APAC 2014
 
02-tradition-ml.pdf
02-tradition-ml.pdf02-tradition-ml.pdf
02-tradition-ml.pdf
 
Use of OpenSees for the development of physics based tsunami fragility functions
Use of OpenSees for the development of physics based tsunami fragility functionsUse of OpenSees for the development of physics based tsunami fragility functions
Use of OpenSees for the development of physics based tsunami fragility functions
 
Three Optimization Tips for C++
Three Optimization Tips for C++Three Optimization Tips for C++
Three Optimization Tips for C++
 
Three Optimization Tips for C++
Three Optimization Tips for C++Three Optimization Tips for C++
Three Optimization Tips for C++
 
A seminar on neo4 j
A seminar on neo4 jA seminar on neo4 j
A seminar on neo4 j
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 
lecture1.ppt
lecture1.pptlecture1.ppt
lecture1.ppt
 

More from Andrei Alexandrescu (6)

Andrei Alexandrescu keynote at CSDN 2007 in Beijing, China
Andrei Alexandrescu keynote at CSDN 2007 in Beijing, ChinaAndrei Alexandrescu keynote at CSDN 2007 in Beijing, China
Andrei Alexandrescu keynote at CSDN 2007 in Beijing, China
 
DConf 2016: What Parnas72 Means for D by Luis Marques
DConf 2016: What Parnas72 Means for D by Luis MarquesDConf 2016: What Parnas72 Means for D by Luis Marques
DConf 2016: What Parnas72 Means for D by Luis Marques
 
DConf 2016: Sociomantic & D by Leandro Lucarella (extended version)
DConf 2016: Sociomantic & D by Leandro Lucarella (extended version)DConf 2016: Sociomantic & D by Leandro Lucarella (extended version)
DConf 2016: Sociomantic & D by Leandro Lucarella (extended version)
 
DConf 2016: Sociomantic & D by Leandro Lucarella
DConf 2016: Sociomantic & D by Leandro LucarellaDConf 2016: Sociomantic & D by Leandro Lucarella
DConf 2016: Sociomantic & D by Leandro Lucarella
 
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury SechetDConf 2016: Bitpacking Like a Madman by Amaury Sechet
DConf 2016: Bitpacking Like a Madman by Amaury Sechet
 
DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright DConf 2016: Keynote by Walter Bright
DConf 2016: Keynote by Walter Bright
 

Recently uploaded

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 

DConf 2016 Opening Keynote

  • 1. © 2016– Andrei Alexandrescu. Do not redistribute. 1 / 33 Opening Keynote Prepared for DConf 2016 Andrei Alexandrescu, Ph.D. 2016-05-04
  • 2. © 2016– Andrei Alexandrescu. Do not redistribute. 2 / 33 Welcome to DConf 2016!
  • 3. Sup © 2016– Andrei Alexandrescu. Do not redistribute. 3 / 33
  • 4.
  • 5. First Five Minutes © 2016– Andrei Alexandrescu. Do not redistribute. 5 / 33 • First five minutes become the next five years • Out of the box experience ◦ Website ◦ Tutorials ◦ Documentation ◦ Libraries • (Self-)Curating dub
  • 6. Scaling Up © 2016– Andrei Alexandrescu. Do not redistribute. 6 / 33 • Many thanks for a great year! ◦ Thanks for being here! ◦ The Foundation is up! • Roles: build czar, sysadmin, webmaster, social media, conference organizer. . . • Enhance the “point of contact” approach • Please get me fired! • I’m in charge of too many things
  • 7. Raising the Bar on Contributions © 2016– Andrei Alexandrescu. Do not redistribute. 7 / 33 • The weird thing about “okay work” • Reasons to NOT pull something: ◦ “Porque no?” ◦ Respected contributor ◦ “That’s a lot of work” ◦ One-liners and many-liners ◦ Renames ◦ Refactorings showing no clear improvement • Churn, illusion of progress
  • 8. Raising the Bar on Contributions © 2016– Andrei Alexandrescu. Do not redistribute. 8 / 33 • Reasons to pull something: ◦ Adds value ◦ Refactors for a net benefit ◦ Fixes a bug “positively” ◦ Makes code simpler ◦ Makes code faster ◦ Automates ◦ Improves documentation • talent × time = win
  • 9. Resource Management © 2016– Andrei Alexandrescu. Do not redistribute. 9 / 33
  • 10. Take the Garbage Out © 2016– Andrei Alexandrescu. Do not redistribute. 10 / 33 Commit to making D great with and without a GC
  • 11. Issues with RC © 2016– Andrei Alexandrescu. Do not redistribute. 11 / 33 • Overall: RC a qualified success story in computing • Make it work with immutable • Make it safe • Make it work with classes and value types • Make it work lazily (COW) ◦ Copies should not have arbitrary cost
  • 12. Basics © 2016– Andrei Alexandrescu. Do not redistribute. 12 / 33 • The C++ way: library smart pointers + Apply to any type − Apply to any type (unsafe) − Needs mutable • Envisioned: ◦ In-language support + library hooks ◦ Attribute @rc ◦ opIncRef(uint), opDecRef(uint)
  • 13. Safety © 2016– Andrei Alexandrescu. Do not redistribute. 13 / 33 • Main issue: unaccounted refs struct RC { int a; ... } void fun(ref RC obj, ref int x) { obj = RC(); ... use x ... } void gun() { RC obj = ...; fun(obj, obj.f); } • Variant: obj is global • Attack: Insert extra incs/decs for ref params • Fuse successive incs/decs where possible • Elide increments where possible
  • 14. immutable © 2016– Andrei Alexandrescu. Do not redistribute. 14 / 33 • Apparent contradiction! ◦ immutable: “I’ll never change, honey” ◦ RC: surreptitious change in metadata • We considered revoking immutable rights for RC objects • If only we had a means to: ◦ allocate metadata along with each object ◦ type metadata independently ◦ access metadata in O(1). . .
  • 15. © 2016– Andrei Alexandrescu. Do not redistribute. 15 / 33 “Why do you completely discard external reference counting approach (i.e. storing refcount in GC/allocator internal data structures bound to allocated memory blocks)?” – Dicebot
  • 16. © 2016– Andrei Alexandrescu. Do not redistribute. 16 / 33 “Never ascribe to malice that which is adequately explained by incompetence.” – Robert J. Hanlon
  • 17. AffixAllocator!. . . AffixAllocator!. . . © 2016– Andrei Alexandrescu. Do not redistribute. 17 / 33 • Part of std.experimental.allocator from day one • AffixAllocator!(GCAllocator, uint): ◦ fronts each allocation with an extra uint ◦ . . . that’s independently typed ◦ Accessible in O(1)! • Use this allocator for creating RC objects
  • 18. import bigo; © 2016– Andrei Alexandrescu. Do not redistribute. 18 / 33
  • 19. “Big O” Notation © 2016– Andrei Alexandrescu. Do not redistribute. 19 / 33 • Compact characterization of algorithms • Growing importance in recent years • Usually confined to documentation • Pen and paper suffices for non-generic code • Better: make it generic and a discoverable part of the API
  • 20. Scaling Naming Conventions © 2016– Andrei Alexandrescu. Do not redistribute. 20 / 33 • Nomenclature approaches don’t scale • removeLinTime, removeLogTime, removeConstTime • Hierarchy of speeds: faster functions subsume slower ones • Sometimes O(·) depends on 2+ parameters • Helpless with HOFs • Doesn’t scale to large APIs • We want to automate this
  • 21. Related Work © 2016– Andrei Alexandrescu. Do not redistribute. 21 / 33 • Java: initially complexity-oblivious APIs ◦ Later: RandomAccess “marker” interface • STL carefully specifies complexity ◦ Archetypal examples: push_front, push_back, operator[] ◦ Syntax complexity follows algo complexity ◦ Undecided on “best effort” vs. “present or not”, e.g. distance
  • 22. Loosely Related Work © 2016– Andrei Alexandrescu. Do not redistribute. 22 / 33 • O(·) analysis part of typechecking (Marion 2011) • Automated Higher-Order Complexity Analysis (Benzinger 2004) • Monotonic State (Pilkiewicz et al 2011)
  • 23. Here © 2016– Andrei Alexandrescu. Do not redistribute. 23 / 33 • User: ◦ Introduces annotations ◦ Defines composition • Framework: ◦ Provides algebra ◦ Propagates attributes ◦ Calculates composition • Notably for higher-order functions ◦ Makes result available by static introspection
  • 24. Synopsis © 2016– Andrei Alexandrescu. Do not redistribute. 24 / 33 // Generic doubly-linked list of E struct DoublyLinkedList(E) { ... // Complexity is O(1) void insertFront(E x) @O(1); } // Generic contiguous array of E struct Array(E) { ... // Complexity is O(n) in the first argument (this) void insertFront(E x) @O("n"); }
  • 25. Synopsis © 2016– Andrei Alexandrescu. Do not redistribute. 25 / 33 // Complexity of insertFrontMany is the complexity of // C.insertFront multiplied by the size of the second // argument. void insertFrontMany(C, E)(ref C container, E[] items) @(complexity!(C.insertFront) * O("n2")) { foreach (item; items) { c.insertFront(item); } }
  • 26. Introspection © 2016– Andrei Alexandrescu. Do not redistribute. 26 / 33 static assert( complexity!(insertFrontMany!MyC) <= O("n2") * log(O("n1")), "Too high complexity for insertFrontMany.");
  • 27. Conventions © 2016– Andrei Alexandrescu. Do not redistribute. 27 / 33 • Unannotated functions are considered O(1) • "nk" for the kth parameter • this is the first parameter • "n" if only one parameter of interest
  • 28. Algebra © 2016– Andrei Alexandrescu. Do not redistribute. 28 / 33 • Credit: Timon Gehr C O i j v pij ij loglij vij • pij, lij positive, pij + lij > 0 • log n, n, n log n, √ n1 + n2 log n2, n2 log n1 . . .
  • 29. Normal Form & Partial Order © 2016– Andrei Alexandrescu. Do not redistribute. 29 / 33 • Normal form for terms: most compact form • A ≤ A′ immediate (compare vars and powers) • T ≤ T′ iff for each atom A in T there’s an atom A′ in T′ with A ≤ A′ • C ≤ C′ iff for each term T in C there’s a term T′ in C′ with T ≤ T′ • Normal form for complexities: no terms are ordered by ≤
  • 30. Operations on Complexities © 2016– Andrei Alexandrescu. Do not redistribute. 30 / 33 • Comparison for equality and ≤ • Addition (add, then normalize) • Multiplication (multiply, then normalize) • Normalization keeps only the fastest-growing terms: O (n + √ m + m log n) + O m2 + log n is O n + m2 + m log n • log just a bit trickier (can’t express log(n1 + n2))
  • 31. log for Complexities © 2016– Andrei Alexandrescu. Do not redistribute. 31 / 33 • Rely on a simple approximation log i j v pij ij loglij vij i j,pij>0 log vij (1) • log log very slow growing, ignore • log(a + b) ≤ log(ab)
  • 32. Implementation © 2016– Andrei Alexandrescu. Do not redistribute. 32 / 33 • Operator overloading (==, <=, +, *) • Pivotal use of compile-time evaluation ◦ Perfect match with attribute expressions • Run-time computation automatically available • Sweet spot between convenience and complexity (sic) • Coming soon!
  • 33. © 2016– Andrei Alexandrescu. Do not redistribute. 33 / 33 One Last Thing