SlideShare ist ein Scribd-Unternehmen logo
1 von 49
Why Angular and React are so fast?
Max Koretskyi aka Wizard
Developer Advocate
2015 20162014 2017 2018
A failed startup
that made me
learn to program
and gave broad
programming
experience
SO activity that
build my
knowledge base
and created a
foundation for
blogging
Angular In Depth
that helped me
build strong
community
and establish
reputation as an
Angular expert
Public speaking
that helped me
meet awesome
people and
become GDE and
MVP
Developer Advocate
job that allows me to
to develop
programming and
marketing skills at
the same time
My 5 years in IT
 maxkoretskyi.com/connecting-the-dots
 https://youtu.be/fT9CZ2QZx5A
Find out more at
Benedikt Meurer, V8 optimizations lead engineer
Alex Rickabught, Angular core team
Dan Ambramov, React core team
Monomorphism Bit fields & Bit masks Bloom filters
Kudos to
Optimization techniques in Angular and React
We use one type for all View nodes so that property
access in loops stay monomorphic!
Misko Hevery, technical lead of Angular
Angular sources comments
Fiber node … shares the same hidden class.
Never add fields outside of construction in `ReactFiber`
Contributing To React Fiber guidelines
Sebastian Markbåge, technical lead of React
• What is a fiber node in React & a view node in Angular?
• What is hidden class and why is it shared by fiber and view nodes?
• What is monomophic property access and why is it important?
Questions we need to answer
Representing a template in Angular
@Component({
template: `
<h1>The title is: {{title}}</h1>
<h2>My hero is: {{hero}}</h2>
`
})
export class AppComponent {
title = 'Tour of Heroes';
hero = 'Windstorm';
}
Type: h1
Type: h2
View Nodes
bindings: {
text: "Tour of Heroes"
}
bindings: {
text: " 'Windstorm"
}
Representing a template in React
class App extends Component {
state = {
title: 'Tour of Heroes',
hero: 'Windstorm'
};
render() {
return (
[
<h1>The title is: {this.state.title}</h1>,
<h2>My hero is: {this.state.hero}</h2>
]
)
}
}
Type: h1
Type: h2
props: {
children: "Tour of Heroes"
}
props: {
children: " Windstorm "
}
Fiber Nodes
Fiber and View nodes are used a lot
when processing changes
properties could easily be accessed
over 10 000* times
function updateNode(node, …) {
let value = node.property;
}
*100 components x 10 elements x 10 function calls
Locating value of an object's property
in memory
is a complicated process
let object = { x: 5, y: 6 };
JSObject
5
6
Property information
Offset: 0
[[Writable]]: true
[[Enumerable]]: true
[[Configurable]]: true
Shape
'x'
'y'
Property information
Offset: 1
[[Writable]]: true
[[Enumerable]]: true
[[Configurable]]: true
Shapes aka Hidden Class (Maps in V8)
5
6
JSObject a
Property
information
Shape
'x'
'y'
Property
information
JSObject b
7
8
let a = { x: 5, y: 6 };
let b = { x: 7, y: 8 };
Shapes help reduce memory footprint
let a = { x: 5, y: 6 }
let b = { x: 7, y: 8 }
b.z = 9;
b.y = 10;
JSObject a
5
6
Shape
'x'
'y'
JSObject b
7
8
Shape
'z'
Shape
'y'
9
10
Transition chains
Inline Caching (IC)
to the rescue
Monomorphic property access
getX(a);
getX(b);
getX(c);
function getX(o) { return o.x; }
let a = { x: 5, y: 6 };
let b = { x: 7, y: 8 };
let b = { x: 7, y: 8 };
a function only saw one type of a shape
Polymorphic property access
getX(a);
getX(b);
getX(c);
getX(D);
function getX(o) { return o.x; }
let a = {x: 5, y: 6};
let b = {y: 7, x: 8}; // different order
let b = {y: 7, x: 8, z: 5}; // new properties
let d = Object.create({}, {}; // different prototype
a function only saw up to 4 different types of a shape
Megamorphic property access
Monomorphic prop access maybe
up to 100 times faster than
megamorphic.
a function saw more than 4 different types of a shape
Frameworks enforce
the same shape (hidden class)
for fiber and view nodes
to enable monomorphic property access
Template node types
Fiber node (React) Template element View node (Angular)
HostComponent HTMLElementNode TypeElement
HostText HTMLTextNode TypeText
FunctionComponent,
ClassComponent
Component Component
type Element {
fieldA;
fieldB;
}
type Text {
fieldC;
field;
}
type Component {
fieldE;
fieldF;
}
Property access is not monormophic
type Node {
tag: nodeType;
fieldA | null;
fieldB | null;
fieldC | null;
fieldD | null;
fieldE | null;
fieldF | null;
}
Property access is monormophic
function beginWork(fiberNode, ...) {
...
switch (fiberNode.tag) {
case FunctionalComponent: {...}
case ClassComponent: {...}
case HostComponent:
return updateHostComponent(fiberNode, ...);
case ...
Branching by node type in React
Bit fields (vector) & Bit masks
Bit field is just an array of bits
let effectTag = 0b01010001; // 81
0 1 0 1 0 0 0 1
Side effects in React fiber are
encoded using bit fields
0 1 0 1 0 1 0 0
Placement
Update
Effects in React Fiber architecture
• Render phase
• Process changes from setState
• Update props on child elements
• Call lifecycle methods (shouldComponentUpdate etc.)
The result of the phase is a tree of fiber nodes marked with side-effects.
• Commit phase (apply effects)
• Update DOM
• Call lifecycle methods (componentDidUpdate etc.)
• Update refs
Before render phase: After render phase:
4..toString(2) = 100
type: 'span'
effectTag: 0
type: 'span'
effectTag: 4
const effectTags = {
Placement = : 0b000000000010;
Update : 0b000000000100;
PlacementAndUpdate : 0b000000000110;
...
}
let effectTag = 0b00000000;
0 0 0 0 0 0 0 0
effectTag = effectTag | effectTags.Update;
0 0 0 0 0 1 0 0
isUpdateEffectSet = !! (effectTag & effectTags.Update);
Write with bitwise OR
Define bitfield
Check with bitwise AND
Branching by effect in React
function updateHostEffects(fiberNode) {
...
const effectTag = fiberNode.effectTag;
if (effectTag & effectTags.Placement) { ... }
if (effectTag & effectTags.PlacementAndUpdate) { ... }
if (effectTag & effectTags.Update) { ... }
...
}
Encoding objects in bit fields
let user = {
first: true,
group: 20,
sortKey: 347843
};
allocations in memory for:
• a standard JS object
• 3 strings for the keys
• 3 values stored in the keys
Encoding objects in bit fields
Field Restrictions on values Bits required
sortKey less than 1M 20 (220 > 1M)
group less than 50 6 (26 = 64)
first boolean 1
00000 0 000000 0000000000000000000
sortKeygroupfirst
32 bits
Encoding objects in bit fields
let user = 0x 05454ec3;
let user = 0b 00000 1 010100 001010100111011000011;
let user = { first: true, group: 20, sortKey: 347843 };
Field Decimal Binary
sortKey 347843 001010100111011000011
group 20 010100
first true 1
Why bother?
• millions of allocations of keys,
objects and values
• a ton of GC (garbage collection)
cleanup after each iteration
• larger and fragmented memory
usage
1 million of objects require
VS
• one typed array for one million
32-integer values
• alsmot zero garbage collection
• smaller and contiguous memory
usage.
Regular JS object Encoded in a bitfield
Bloom filters
is element in the set?
DEFINITELY NO MAYBE
100% probability varying probability
data structure that answers the question
0 1 0 0 0 0 1 0
Is element in a set? Is bits [n1,n2…n] set?
Each element is encoded in a bit field
let value = "Jonh";
calculateBit1Number(value); // 2
calculateBit2Number(value); // 7
John - 2
0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0
Using bloom filter for string values
Anna – 1
Tom - 4
[ "John", "Anna", "Tom" ]
let calculateBit1Value = (value) => value.charCodeAt(0) % 8
Why "yes" is not guaranteed?
Anna – 1 0 0 0 0 0 0 0 1
0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 0
collisions
Tom - 4
John - 2
Jane - 2
Less slots, more collisions
How to increase
probability of "Yes"?
Anna – 1, 6 0 0 1 0 0 0 0 1
0 1 0 0 1 0 0 0
0 0 0 0 0 0 1 1
0 1 0 0 0 0 1 0
no
collisionsTom – 4, 7
John – 2, 7
Jane – 2, 1
More slots, less collisions
Where does Angular use this?
Dependency Injection
mechanism
ServiceA
ServiceB
ServiceC
constructor( ServiceA ) {}
Injector
ServiceD
Hierarchical
injectors
Dashboard
component
Widget
component
SiteAnalytics
component
WidgetManager
Injector
Injector
WidgetManager
Injector
Is here?
no – go up
Is here?
no – go up
Is here?
yes – resolve
Bloom
filters
Injector
Dashboard
component
Widget
component
SiteAnalytics
component
WidgetManager
WidgetManager
Injector
Is here?
no – go up
Is here?
no – go up
resolve
Injector
Bloom
filter
Bloom
filter
Bloom
filter
Is here?
maybe –
chec injector
Ask me anything
Angular In Depth
conference
Kyiv,
15th of June
Follow me to learn fundamentals
@maxim_koretskyi
maxkoretskyi
maxkoretskyi.com
Max Koretskyi "Why are Angular and React so fast?"

Weitere ähnliche Inhalte

Was ist angesagt?

Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersJoris Verbogt
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181Mahmoud Samir Fayed
 
科特林λ學
科特林λ學科特林λ學
科特林λ學彥彬 洪
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-CひとめぐりKenji Kinukawa
 
2 introduction toentitybeans
2 introduction toentitybeans2 introduction toentitybeans
2 introduction toentitybeansashishkirpan
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderAndres Almiray
 
The Ring programming language version 1.4.1 book - Part 11 of 31
The Ring programming language version 1.4.1 book - Part 11 of 31The Ring programming language version 1.4.1 book - Part 11 of 31
The Ring programming language version 1.4.1 book - Part 11 of 31Mahmoud Samir Fayed
 
The Ring programming language version 1.3 book - Part 29 of 88
The Ring programming language version 1.3 book - Part 29 of 88The Ring programming language version 1.3 book - Part 29 of 88
The Ring programming language version 1.3 book - Part 29 of 88Mahmoud Samir Fayed
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Scott Wlaschin
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptMiao Siyu
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functionsPrincess Sam
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureDmytro Zaitsev
 

Was ist angesagt? (19)

Objective-C Crash Course for Web Developers
Objective-C Crash Course for Web DevelopersObjective-C Crash Course for Web Developers
Objective-C Crash Course for Web Developers
 
Scala best practices
Scala best practicesScala best practices
Scala best practices
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185
 
The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181The Ring programming language version 1.5.2 book - Part 37 of 181
The Ring programming language version 1.5.2 book - Part 37 of 181
 
C++ L11-Polymorphism
C++ L11-PolymorphismC++ L11-Polymorphism
C++ L11-Polymorphism
 
科特林λ學
科特林λ學科特林λ學
科特林λ學
 
Objective-Cひとめぐり
Objective-CひとめぐりObjective-Cひとめぐり
Objective-Cひとめぐり
 
Es.next
Es.nextEs.next
Es.next
 
2 introduction toentitybeans
2 introduction toentitybeans2 introduction toentitybeans
2 introduction toentitybeans
 
CodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilderCodeMash - Building Rich Apps with Groovy SwingBuilder
CodeMash - Building Rich Apps with Groovy SwingBuilder
 
Composite Pattern
Composite PatternComposite Pattern
Composite Pattern
 
The Ring programming language version 1.4.1 book - Part 11 of 31
The Ring programming language version 1.4.1 book - Part 11 of 31The Ring programming language version 1.4.1 book - Part 11 of 31
The Ring programming language version 1.4.1 book - Part 11 of 31
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
The Ring programming language version 1.3 book - Part 29 of 88
The Ring programming language version 1.3 book - Part 29 of 88The Ring programming language version 1.3 book - Part 29 of 88
The Ring programming language version 1.3 book - Part 29 of 88
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 
Lec 45.46- virtual.functions
Lec 45.46- virtual.functionsLec 45.46- virtual.functions
Lec 45.46- virtual.functions
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasure
 

Ähnlich wie Max Koretskyi "Why are Angular and React so fast?"

Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of JavascriptTarek Yehia
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryjanet736113
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTechAntya Dev
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftMichele Titolo
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responsesdarrelmiller71
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sitesgoodfriday
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS EngineZongXian Shen
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin Vasil Remeniuk
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Libraryrsnarayanan
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Watersmichael.labriola
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive ShellGiovanni Lodi
 
Behavior driven oop
Behavior driven oopBehavior driven oop
Behavior driven oopPiyush Verma
 

Ähnlich wie Max Koretskyi "Why are Angular and React so fast?" (20)

Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Art of Javascript
Art of JavascriptArt of Javascript
Art of Javascript
 
react-slides.pdf
react-slides.pdfreact-slides.pdf
react-slides.pdf
 
react-slides.pdf gives information about react library
react-slides.pdf gives information about react libraryreact-slides.pdf gives information about react library
react-slides.pdf gives information about react library
 
Adopting F# at SBTech
Adopting F# at SBTechAdopting F# at SBTech
Adopting F# at SBTech
 
react-slides.pptx
react-slides.pptxreact-slides.pptx
react-slides.pptx
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Building High Performance Web Applications and Sites
Building High Performance Web Applications and SitesBuilding High Performance Web Applications and Sites
Building High Performance Web Applications and Sites
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
(COSCUP 2015) A Beginner's Journey to Mozilla SpiderMonkey JS Engine
 
"Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin "Scala in Goozy", Alexey Zlobin
"Scala in Goozy", Alexey Zlobin
 
J Query The Write Less Do More Javascript Library
J Query   The Write Less Do More Javascript LibraryJ Query   The Write Less Do More Javascript Library
J Query The Write Less Do More Javascript Library
 
Java Performance Tuning
Java Performance TuningJava Performance Tuning
Java Performance Tuning
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive Shell
 
Behavior driven oop
Behavior driven oopBehavior driven oop
Behavior driven oop
 

Mehr von Fwdays

"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y..."How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...Fwdays
 
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil TopchiiFwdays
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro Spodarets"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro SpodaretsFwdays
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
"Distributed graphs and microservices in Prom.ua", Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua", Maksym KindritskyiFwdays
 
"Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl..."Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl...Fwdays
 
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T..."How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...Fwdays
 
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ..."The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...Fwdays
 
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu..."[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...Fwdays
 
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care..."[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...Fwdays
 
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"..."4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...Fwdays
 
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast..."Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...Fwdays
 
"Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others..."Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others...Fwdays
 
"Mission (im) possible: How to get an offer in 2024?", Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?", Oleksandra MyronovaFwdays
 
"Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv..."Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv...Fwdays
 
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin..."How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...Fwdays
 

Mehr von Fwdays (20)

"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y..."How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
"How Preply reduced ML model development time from 1 month to 1 day",Yevhen Y...
 
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
"GenAI Apps: Our Journey from Ideas to Production Excellence",Danil Topchii
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro Spodarets"What is a RAG system and how to build it",Dmytro Spodarets
"What is a RAG system and how to build it",Dmytro Spodarets
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
"Distributed graphs and microservices in Prom.ua", Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi"Distributed graphs and microservices in Prom.ua",  Maksym Kindritskyi
"Distributed graphs and microservices in Prom.ua", Maksym Kindritskyi
 
"Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl..."Rethinking the existing data loading and processing process as an ETL exampl...
"Rethinking the existing data loading and processing process as an ETL exampl...
 
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T..."How Ukrainian IT specialist can go on vacation abroad without crossing the T...
"How Ukrainian IT specialist can go on vacation abroad without crossing the T...
 
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ..."The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
"The Strength of Being Vulnerable: the experience from CIA, Tesla and Uber", ...
 
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu..."[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
"[QUICK TALK] Radical candor: how to achieve results faster thanks to a cultu...
 
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care..."[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
"[QUICK TALK] PDP Plan, the only one door to raise your salary and boost care...
 
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"..."4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
"4 horsemen of the apocalypse of working relationships (+ antidotes to them)"...
 
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast..."Reconnecting with Purpose: Rediscovering Job Interest after Burnout",  Anast...
"Reconnecting with Purpose: Rediscovering Job Interest after Burnout", Anast...
 
"Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others..."Mentoring 101: How to effectively invest experience in the success of others...
"Mentoring 101: How to effectively invest experience in the success of others...
 
"Mission (im) possible: How to get an offer in 2024?", Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova"Mission (im) possible: How to get an offer in 2024?",  Oleksandra Myronova
"Mission (im) possible: How to get an offer in 2024?", Oleksandra Myronova
 
"Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv..."Why have we learned how to package products, but not how to 'package ourselv...
"Why have we learned how to package products, but not how to 'package ourselv...
 
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin..."How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
"How to tame the dragon, or leadership with imposter syndrome", Oleksandr Zin...
 

Kürzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Max Koretskyi "Why are Angular and React so fast?"

  • 1. Why Angular and React are so fast? Max Koretskyi aka Wizard Developer Advocate
  • 2. 2015 20162014 2017 2018 A failed startup that made me learn to program and gave broad programming experience SO activity that build my knowledge base and created a foundation for blogging Angular In Depth that helped me build strong community and establish reputation as an Angular expert Public speaking that helped me meet awesome people and become GDE and MVP Developer Advocate job that allows me to to develop programming and marketing skills at the same time My 5 years in IT
  • 4. Benedikt Meurer, V8 optimizations lead engineer Alex Rickabught, Angular core team Dan Ambramov, React core team Monomorphism Bit fields & Bit masks Bloom filters Kudos to Optimization techniques in Angular and React
  • 5. We use one type for all View nodes so that property access in loops stay monomorphic! Misko Hevery, technical lead of Angular Angular sources comments
  • 6. Fiber node … shares the same hidden class. Never add fields outside of construction in `ReactFiber` Contributing To React Fiber guidelines Sebastian Markbåge, technical lead of React
  • 7. • What is a fiber node in React & a view node in Angular? • What is hidden class and why is it shared by fiber and view nodes? • What is monomophic property access and why is it important? Questions we need to answer
  • 8. Representing a template in Angular @Component({ template: ` <h1>The title is: {{title}}</h1> <h2>My hero is: {{hero}}</h2> ` }) export class AppComponent { title = 'Tour of Heroes'; hero = 'Windstorm'; } Type: h1 Type: h2 View Nodes bindings: { text: "Tour of Heroes" } bindings: { text: " 'Windstorm" }
  • 9. Representing a template in React class App extends Component { state = { title: 'Tour of Heroes', hero: 'Windstorm' }; render() { return ( [ <h1>The title is: {this.state.title}</h1>, <h2>My hero is: {this.state.hero}</h2> ] ) } } Type: h1 Type: h2 props: { children: "Tour of Heroes" } props: { children: " Windstorm " } Fiber Nodes
  • 10. Fiber and View nodes are used a lot when processing changes properties could easily be accessed over 10 000* times function updateNode(node, …) { let value = node.property; } *100 components x 10 elements x 10 function calls
  • 11. Locating value of an object's property in memory is a complicated process
  • 12. let object = { x: 5, y: 6 }; JSObject 5 6 Property information Offset: 0 [[Writable]]: true [[Enumerable]]: true [[Configurable]]: true Shape 'x' 'y' Property information Offset: 1 [[Writable]]: true [[Enumerable]]: true [[Configurable]]: true Shapes aka Hidden Class (Maps in V8)
  • 13. 5 6 JSObject a Property information Shape 'x' 'y' Property information JSObject b 7 8 let a = { x: 5, y: 6 }; let b = { x: 7, y: 8 }; Shapes help reduce memory footprint
  • 14. let a = { x: 5, y: 6 } let b = { x: 7, y: 8 } b.z = 9; b.y = 10; JSObject a 5 6 Shape 'x' 'y' JSObject b 7 8 Shape 'z' Shape 'y' 9 10 Transition chains
  • 16. Monomorphic property access getX(a); getX(b); getX(c); function getX(o) { return o.x; } let a = { x: 5, y: 6 }; let b = { x: 7, y: 8 }; let b = { x: 7, y: 8 }; a function only saw one type of a shape
  • 17. Polymorphic property access getX(a); getX(b); getX(c); getX(D); function getX(o) { return o.x; } let a = {x: 5, y: 6}; let b = {y: 7, x: 8}; // different order let b = {y: 7, x: 8, z: 5}; // new properties let d = Object.create({}, {}; // different prototype a function only saw up to 4 different types of a shape
  • 18. Megamorphic property access Monomorphic prop access maybe up to 100 times faster than megamorphic. a function saw more than 4 different types of a shape
  • 19. Frameworks enforce the same shape (hidden class) for fiber and view nodes to enable monomorphic property access
  • 20. Template node types Fiber node (React) Template element View node (Angular) HostComponent HTMLElementNode TypeElement HostText HTMLTextNode TypeText FunctionComponent, ClassComponent Component Component
  • 21. type Element { fieldA; fieldB; } type Text { fieldC; field; } type Component { fieldE; fieldF; } Property access is not monormophic type Node { tag: nodeType; fieldA | null; fieldB | null; fieldC | null; fieldD | null; fieldE | null; fieldF | null; } Property access is monormophic
  • 22. function beginWork(fiberNode, ...) { ... switch (fiberNode.tag) { case FunctionalComponent: {...} case ClassComponent: {...} case HostComponent: return updateHostComponent(fiberNode, ...); case ... Branching by node type in React
  • 23. Bit fields (vector) & Bit masks
  • 24. Bit field is just an array of bits let effectTag = 0b01010001; // 81 0 1 0 1 0 0 0 1
  • 25. Side effects in React fiber are encoded using bit fields 0 1 0 1 0 1 0 0 Placement Update
  • 26. Effects in React Fiber architecture • Render phase • Process changes from setState • Update props on child elements • Call lifecycle methods (shouldComponentUpdate etc.) The result of the phase is a tree of fiber nodes marked with side-effects. • Commit phase (apply effects) • Update DOM • Call lifecycle methods (componentDidUpdate etc.) • Update refs
  • 27. Before render phase: After render phase: 4..toString(2) = 100 type: 'span' effectTag: 0 type: 'span' effectTag: 4 const effectTags = { Placement = : 0b000000000010; Update : 0b000000000100; PlacementAndUpdate : 0b000000000110; ... }
  • 28. let effectTag = 0b00000000; 0 0 0 0 0 0 0 0 effectTag = effectTag | effectTags.Update; 0 0 0 0 0 1 0 0 isUpdateEffectSet = !! (effectTag & effectTags.Update); Write with bitwise OR Define bitfield Check with bitwise AND
  • 29. Branching by effect in React function updateHostEffects(fiberNode) { ... const effectTag = fiberNode.effectTag; if (effectTag & effectTags.Placement) { ... } if (effectTag & effectTags.PlacementAndUpdate) { ... } if (effectTag & effectTags.Update) { ... } ... }
  • 30. Encoding objects in bit fields let user = { first: true, group: 20, sortKey: 347843 }; allocations in memory for: • a standard JS object • 3 strings for the keys • 3 values stored in the keys
  • 31. Encoding objects in bit fields Field Restrictions on values Bits required sortKey less than 1M 20 (220 > 1M) group less than 50 6 (26 = 64) first boolean 1 00000 0 000000 0000000000000000000 sortKeygroupfirst 32 bits
  • 32. Encoding objects in bit fields let user = 0x 05454ec3; let user = 0b 00000 1 010100 001010100111011000011; let user = { first: true, group: 20, sortKey: 347843 }; Field Decimal Binary sortKey 347843 001010100111011000011 group 20 010100 first true 1
  • 34. • millions of allocations of keys, objects and values • a ton of GC (garbage collection) cleanup after each iteration • larger and fragmented memory usage 1 million of objects require VS • one typed array for one million 32-integer values • alsmot zero garbage collection • smaller and contiguous memory usage. Regular JS object Encoded in a bitfield
  • 35. Bloom filters is element in the set? DEFINITELY NO MAYBE 100% probability varying probability data structure that answers the question
  • 36. 0 1 0 0 0 0 1 0 Is element in a set? Is bits [n1,n2…n] set? Each element is encoded in a bit field let value = "Jonh"; calculateBit1Number(value); // 2 calculateBit2Number(value); // 7
  • 37. John - 2 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 Using bloom filter for string values Anna – 1 Tom - 4 [ "John", "Anna", "Tom" ] let calculateBit1Value = (value) => value.charCodeAt(0) % 8
  • 38. Why "yes" is not guaranteed?
  • 39. Anna – 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 collisions Tom - 4 John - 2 Jane - 2 Less slots, more collisions
  • 41. Anna – 1, 6 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 0 no collisionsTom – 4, 7 John – 2, 7 Jane – 2, 1 More slots, less collisions
  • 42. Where does Angular use this? Dependency Injection mechanism
  • 45. Bloom filters Injector Dashboard component Widget component SiteAnalytics component WidgetManager WidgetManager Injector Is here? no – go up Is here? no – go up resolve Injector Bloom filter Bloom filter Bloom filter Is here? maybe – chec injector
  • 48. Follow me to learn fundamentals @maxim_koretskyi maxkoretskyi maxkoretskyi.com

Hinweis der Redaktion

  1. История имени Идея доклада - Первый раз выступление на русском языке и необходимость улыбаться
  2. Использует много техник, мономорфизм самый сложный для понимания
  3. Как я натолкнулся на гайдлайны для контрибьюторов в React 16 и новее. Кто понимает ее?
  4. - updateNode эквиваленты в Angular и React во время процессинга изменений, механизм CD вкратце
  5. - Много логических шагов, инструкций процессору в разы больше
  6. Каждый объект в JS внутри виртуалной машины представлен структурой данных, которая называет Shape/Hidden Class/Map. Shape определяет структуру объекта JS и расположение значений полей в памяти.
  7. В независимости от количества объектов, мы храним информацию обо всех объектах один раз.
  8. Adding/removing properties changes the Shape and creates a transition chain. Objects with different prototypes have different shapes
  9. Оптимизация с помощью Inline Caching. Виртуальные машины используют его что-то бы запомнить и закешировать информацию о том, как найти значение какого-либо поля объекта. И понятия мономорфизма и hidden classes связано именно с этими техниками.
  10. They keep the same shape for a View node (Angular) and a Fiber node (React) in all function calls.
  11. Effects describe the work that needs to be done during the following commit phase.
  12. To create this object, a JS engine has to allocate a standard JS object, allocate 3 strings for the keys and store the 3 values. Given that I know as the developer of this app that the sortKey field is never larger than, say, 1 million and the group is at most 50 and the first is a boolean, which is 1 or 0. I can use this info to put all this info into a single 32-bit integer.  sortKey can fit inside 20 bits (220 > 1M), group can fit into 6 bits (26 = 64) and first can fit into a single bit, total 27 bits. To create this value, the JS engine has to … allocate nothing (in optimised passes), it's just an integer that fits comfortably in a register inside the CPU, we even have 5 bits to spare! ;) I can now use the bit masking and insertion techniques you mentioned to read/write data in these values (did I mention that bit ops are single instructions on the CPU?)
  13. The problem is collisions. 2 letters. Hash functions are usually used to produce some number. But it can be anything. Even a simple counter. And that's what Angular does.
  14. The problem is collisions. 2 letters. Hash functions are usually used to produce some number. But it can be anything. Even a simple counter. And that's what Angular does.
  15. The problem is collisions. 2 letters. Hash functions are usually used to produce some number. But it can be anything. Even a simple counter. And that's what Angular does.
  16. The problem is collisions. 2 letters. Hash functions are usually used to produce some number. But it can be anything. Even a simple counter. And that's what Angular does.
  17. Dependency Injection (DI), is an important application design pattern. We use in ag-Grid. It significantly simplifies architecture. Angular has its own DI framework, which is typically used in the design of Angular applications to increase their efficiency and modularity.
  18. Key part of it is an injector. It's basically a container that knows how to instantiate a particular service and which dependencies to pass to the service. The Angular dependency injection system is hierarchical.
  19. If you have any questions, I'll be sitting in the experts room tomorrow at 3 pm. Or you can catch me in the hallways, I'll be wearing this T-shirt so you can recognize me.
  20. For more in-depth information follow me on Twitter. I promise I won’t waste your time. I’ll write a follow-up article on change detection. So stay tuned and expect some tweets about it quite soon.
  21. I hope that the knowledge we covered today has awaken your curiosity and thirst for knowledge. Never stop learning and you'll be constantly reaching new heights. I want you all guys to become extraordinary engineers. Thanks for your attention and good luck!