Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance

Ivan Chepurnyi
Ivan ChepurnyiIndependent Technical Consultant & Trainer em EcomDev BV
MAGENTO 2
LAYOUT AND CODE COMPILATION
FOR PERFORMANCE
 
by Ivan Chepurnyi
WHAT? COMPILATION?
COMPLEX ALGORITHMSSIMPLE
WHAT MAKES THEM COMPLEX?
REPEATED DATA PROCESSING
// ... some xml/json/yaml file initialization
foreach ($loadedData as $item) {
$this->process($item);
}
NESTED LOOPS
foreach ($data as $item) {
$row = [];
foreach ($columns as $column) {
$row[] = $column->export($item);
}
$csv->write($row);
}
COMPLEX DEPENDENCY TREE
class ClassOne
{
public function __construct(ClassTwo $dependency) {}
}
class ClassTwo
{
public function __construct(ClassThree $dependency) {}
}
class ClassThree
{
public function __construct(ClassFour $dependencyOne, ClassFive $dependen
}
// ..
HOW CAN WE SOLVE IT?
REPEATED DATA PROCESSING
Translate your XML/JSON/YAML file into executable PHP
code and include it when you need processed structure
NESTED LOOPS
Pre-compile second loop and execute it within the main one
COMPLEX DEPENDENCY TREE
Resolve dependencies and compile resolution into
executable code
BUT COMPILATION LOOKS UGLY...
You need to create PHP code within PHP code
You need to write it to external file
You need to include that file inside of your code
I WAS LOOKING FOR A LIBRARY
Didn't find one... So I wrote it myself.
ECOMDEVCOMPILER
Created to wrap writing PHP code within PHP
Automatically stores compiled code
Automatically validates source and re-compiles code
when needed
Provides easy to use API to create parsers, builders and
executors
INSTALLATION
1. Available as a composer dependency
2. Instantiate it directly or via DI container.
composer require "ecomdev/compiler"
SOME EXAMPLES
COMPILE XML INTO PHP
XML FILE
<objects>
<item id="object_one" type="object" />
<item id="object_two" type="object" />
<item id="object_three" type="object" />
<type id="object" class="SomeClassName"/>
</objects>
PARSER
use EcomDevCompilerStatementBuilder;
class Parser implements EcomDevCompilerParserInterface
{
// .. constructor with builder as dependency
public function parse($value)
{
$xml = simplexml_load_string($value);
$info = $this->readXml($xml);
return $this->getPhpCode($info, $this->builder);
}
// .. other methods
}
PARSE XML DATA
private function readXml($xml)
{
$info = [];
foreach ($xml->children() as $node) {
if ($node->getName() === 'type') {
$info['types'][(string)$node->id] = (string)$node->class;
} elseif ($node->getName() === 'object') {
$info['objects'][(string)$node->id] = (string)$node->type;
}
}
return $info;
}
CREATE PHP CODE
private function getPhpCode($info, $builder) {
$compiledArray = [];
foreach ($info['objects'] as $objectId => $type) {
$compiledArray[$objectId] = $builder->instance($info['types'][
}
return $builder->container(
$builder->returnValue($compiledArray)
);
}
COMPILED PHP FILE
return [
'object_one' => new SomeClassName(),
'object_two' => new SomeClassName(),
'object_three' => new SomeClassName()
];
NESTED LOOP SIMPLIFYING
YOUR CONSTRUCTOR
public function __construct(
EcomDevCompilerBuilder $builder,
EcomDevCompilerCompiler $compiler)
{
$this->builder = $builder;
$this->compiler = $compiler;
}
EXPORT METHOD
public function export($data, $columns)
{
$statements = $this->compileColumns($columns, $this->builder);
$source = new EcomDevCompilerSourceStaticData(
'your_id', 'your_checksum', $statements
);
$reference = $this->compiler->compile($source);
$closure = $this->compiler->interpret($reference);
foreach ($data as $item) {
$row = $closure($item, $columns);
}
}
COMPILATION METHOD
public function compileColumns($columns, $builder)
{
$item = $builder->variable('item');
$compiledArray = [];
foreach ($columns as $id => $column) {
$compiledArray[] = $builder->chainVariable('columns')[$id]
->export($item);
}
$closure = $builder->closure(
[$item, $builder->variable('columns')],
$builder->container([$builder->returnValue($compiledArray)])
);
return $builder->container([$builder->returnValue($closure)]);
}
RESULT
return function ($item, $columns) {
return [
$columns['id1']->export($item),
$columns['id2']->export($item),
$columns['id3']->export($item),
// ...
];
};
MAIN COMPONENTS
CompilerInterface - Compiler instance
StorageInterface - Stores compiled files
SourceInterface - Provider of data (File, String,
StaticData)
ParserInterface - Parser of data
ObjectBuilderInterface - Bound builder for included files
AND SOME SWEET STUFF...
EXPORTABLE OBJECTS
class SomeClass implements EcomDevCompilerExportableInterface
{
public function __construct($foo, $bar) { /* */ }
public function export() {
return [
'foo' => $this->foo,
'bar' => $this->bar
];
}
}
Will be automatically compiled into:
new SomeClass('fooValue', 'barValue');
MAGENTO 2.0
LAYOUT COMPILATION IS A MUST
WHY? BECAUSE OF ITS ALGORITHM
LAYOUT CACHING
Every handle that is added to the
MagentoFrameworkViewResult changes the cache key
for the whole generated structure.
LAYOUT GENERATION
Scheduled structure is generated from XML object at all
times
SOLUTION
1. Make every handle a compiled php code
2. Include compiled handles at loading phase
GOOD NEWS
I am already working on it
Will be release in April 2016
GITHUB
COMPILER LIBRARY FOR M2
https://github.com/EcomDev/compiler
LAYOUT COMPILER FOR M1
https://github.com/EcomDev/EcomDev_LayoutCompiler
LAYOUT COMPILER FOR M2
Coming soon
Q&A
@IvanChepurnyi
ivan@ecomdev.org
1 de 38

Recomendados

Optimizing Magento by Preloading Data por
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading DataIvan Chepurnyi
1.9K visualizações28 slides
Using of TDD practices for Magento por
Using of TDD practices for MagentoUsing of TDD practices for Magento
Using of TDD practices for MagentoIvan Chepurnyi
6.7K visualizações20 slides
Система рендеринга в Magento por
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в MagentoMagecom Ukraine
652 visualizações17 slides
AngularJS Compile Process por
AngularJS Compile ProcessAngularJS Compile Process
AngularJS Compile ProcessEyal Vardi
11.2K visualizações10 slides
Doctrine 2 por
Doctrine 2Doctrine 2
Doctrine 2zfconfua
1.7K visualizações40 slides
Get AngularJS Started! por
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!Dzmitry Ivashutsin
1K visualizações37 slides

Mais conteúdo relacionado

Mais procurados

The IoC Hydra - Dutch PHP Conference 2016 por
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016Kacper Gunia
1.2K visualizações127 slides
Forget about index.php and build you applications around HTTP! por
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!Kacper Gunia
5.7K visualizações128 slides
AngularJS Directives por
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
11.9K visualizações38 slides
AngulrJS Overview por
AngulrJS OverviewAngulrJS Overview
AngulrJS OverviewEyal Vardi
10.8K visualizações17 slides
The IoC Hydra por
The IoC HydraThe IoC Hydra
The IoC HydraKacper Gunia
3.3K visualizações124 slides
Rich domain model with symfony 2.5 and doctrine 2.5 por
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
12K visualizações90 slides

Mais procurados(20)

The IoC Hydra - Dutch PHP Conference 2016 por Kacper Gunia
The IoC Hydra - Dutch PHP Conference 2016The IoC Hydra - Dutch PHP Conference 2016
The IoC Hydra - Dutch PHP Conference 2016
Kacper Gunia1.2K visualizações
Forget about index.php and build you applications around HTTP! por Kacper Gunia
Forget about index.php and build you applications around HTTP!Forget about index.php and build you applications around HTTP!
Forget about index.php and build you applications around HTTP!
Kacper Gunia5.7K visualizações
AngularJS Directives por Eyal Vardi
AngularJS DirectivesAngularJS Directives
AngularJS Directives
Eyal Vardi11.9K visualizações
AngulrJS Overview por Eyal Vardi
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
Eyal Vardi10.8K visualizações
The IoC Hydra por Kacper Gunia
The IoC HydraThe IoC Hydra
The IoC Hydra
Kacper Gunia3.3K visualizações
Rich domain model with symfony 2.5 and doctrine 2.5 por Leonardo Proietti
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti12K visualizações
Min-Maxing Software Costs - Laracon EU 2015 por Konstantin Kudryashov
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
Konstantin Kudryashov14.2K visualizações
jQuery in 15 minutes por Simon Willison
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
Simon Willison41.5K visualizações
Doctrine For Beginners por Jonathan Wage
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage1.5K visualizações
Advanced php testing in action por Jace Ju
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
Jace Ju2.1K visualizações
Rich Model And Layered Architecture in SF2 Application por Kirill Chebunin
Rich Model And Layered Architecture in SF2 ApplicationRich Model And Layered Architecture in SF2 Application
Rich Model And Layered Architecture in SF2 Application
Kirill Chebunin3.7K visualizações
Symfony2 Building on Alpha / Beta technology por Daniel Knell
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell750 visualizações
Sprout core and performance por Yehuda Katz
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz1.4K visualizações
Beyond symfony 1.2 (Symfony Camp 2008) por Fabien Potencier
Beyond symfony 1.2 (Symfony Camp 2008)Beyond symfony 1.2 (Symfony Camp 2008)
Beyond symfony 1.2 (Symfony Camp 2008)
Fabien Potencier58.8K visualizações
IndexedDB - Querying and Performance por Parashuram N
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
Parashuram N11.9K visualizações
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need por Kacper Gunia
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia50.4K visualizações
Decoupling the Ulabox.com monolith. From CRUD to DDD por Aleix Vergés
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
Aleix Vergés1.8K visualizações
Design Patterns in PHP5 por Wildan Maulana
Design Patterns in PHP5 Design Patterns in PHP5
Design Patterns in PHP5
Wildan Maulana1.7K visualizações
Forget about Index.php and build you applications around HTTP - PHPers Cracow por Kacper Gunia
Forget about Index.php and build you applications around HTTP - PHPers CracowForget about Index.php and build you applications around HTTP - PHPers Cracow
Forget about Index.php and build you applications around HTTP - PHPers Cracow
Kacper Gunia3.2K visualizações

Destaque

Real use cases of performance optimization in magento 2 por
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2Max Pronko
22.7K visualizações65 slides
Oleh Kobchenko - Configure Magento 2 to get maximum performance por
Oleh Kobchenko - Configure Magento 2 to get maximum performanceOleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performanceMeet Magento Italy
32K visualizações31 slides
Phpworld.2015 scaling magento por
Phpworld.2015 scaling magentoPhpworld.2015 scaling magento
Phpworld.2015 scaling magentoMathew Beane
36K visualizações125 slides
Making Magento flying like a rocket! (A set of valuable tips for developers) por
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)Ivan Chepurnyi
36.6K visualizações57 slides
Magento 2.0: Prepare yourself for a new way of module development por
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module developmentIvan Chepurnyi
5.8K visualizações44 slides
Hidden Secrets of Magento Price Rules por
Hidden Secrets of Magento Price RulesHidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price RulesIvan Chepurnyi
27.5K visualizações27 slides

Destaque(8)

Real use cases of performance optimization in magento 2 por Max Pronko
Real use cases of performance optimization in magento 2Real use cases of performance optimization in magento 2
Real use cases of performance optimization in magento 2
Max Pronko22.7K visualizações
Oleh Kobchenko - Configure Magento 2 to get maximum performance por Meet Magento Italy
Oleh Kobchenko - Configure Magento 2 to get maximum performanceOleh Kobchenko - Configure Magento 2 to get maximum performance
Oleh Kobchenko - Configure Magento 2 to get maximum performance
Meet Magento Italy32K visualizações
Phpworld.2015 scaling magento por Mathew Beane
Phpworld.2015 scaling magentoPhpworld.2015 scaling magento
Phpworld.2015 scaling magento
Mathew Beane36K visualizações
Making Magento flying like a rocket! (A set of valuable tips for developers) por Ivan Chepurnyi
Making Magento flying like a rocket! (A set of valuable tips for developers)Making Magento flying like a rocket! (A set of valuable tips for developers)
Making Magento flying like a rocket! (A set of valuable tips for developers)
Ivan Chepurnyi36.6K visualizações
Magento 2.0: Prepare yourself for a new way of module development por Ivan Chepurnyi
Magento 2.0: Prepare yourself for a new way of module developmentMagento 2.0: Prepare yourself for a new way of module development
Magento 2.0: Prepare yourself for a new way of module development
Ivan Chepurnyi5.8K visualizações
Hidden Secrets of Magento Price Rules por Ivan Chepurnyi
Hidden Secrets of Magento Price RulesHidden Secrets of Magento Price Rules
Hidden Secrets of Magento Price Rules
Ivan Chepurnyi27.5K visualizações
Varnish Cache and its usage in the real world! por Ivan Chepurnyi
Varnish Cache and its usage in the real world!Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!
Ivan Chepurnyi10.8K visualizações
Magento Indexes por Ivan Chepurnyi
Magento IndexesMagento Indexes
Magento Indexes
Ivan Chepurnyi16.3K visualizações

Similar a Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance

Unittests für Dummies por
Unittests für DummiesUnittests für Dummies
Unittests für DummiesLars Jankowfsky
1K visualizações28 slides
Why is crud a bad idea - focus on real scenarios por
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosDivante
741 visualizações27 slides
Adding Dependency Injection to Legacy Applications por
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
1.8K visualizações77 slides
Design Patterns avec PHP 5.3, Symfony et Pimple por
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
6.1K visualizações68 slides
Ioc container | Hannes Van De Vreken | CODEiD por
Ioc container | Hannes Van De Vreken | CODEiDIoc container | Hannes Van De Vreken | CODEiD
Ioc container | Hannes Van De Vreken | CODEiDCODEiD PHP Community
265 visualizações127 slides
The History of PHPersistence por
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
2.3K visualizações75 slides

Similar a Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance(20)

Unittests für Dummies por Lars Jankowfsky
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
Lars Jankowfsky1K visualizações
Why is crud a bad idea - focus on real scenarios por Divante
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante741 visualizações
Adding Dependency Injection to Legacy Applications por Sam Hennessy
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
Sam Hennessy1.8K visualizações
Design Patterns avec PHP 5.3, Symfony et Pimple por Hugo Hamon
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
Hugo Hamon6.1K visualizações
Ioc container | Hannes Van De Vreken | CODEiD por CODEiD PHP Community
Ioc container | Hannes Van De Vreken | CODEiDIoc container | Hannes Van De Vreken | CODEiD
Ioc container | Hannes Van De Vreken | CODEiD
CODEiD PHP Community265 visualizações
The History of PHPersistence por Hugo Hamon
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
Hugo Hamon2.3K visualizações
Intermediate PHP por Bradley Holt
Intermediate PHPIntermediate PHP
Intermediate PHP
Bradley Holt2.5K visualizações
PHPCon 2016: PHP7 by Witek Adamus / XSolve por XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve1K visualizações
The Origin of Lithium por Nate Abele
The Origin of LithiumThe Origin of Lithium
The Origin of Lithium
Nate Abele8.4K visualizações
JavaScript for PHP developers por Stoyan Stefanov
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov15.6K visualizações
How Kris Writes Symfony Apps por Kris Wallsmith
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
Kris Wallsmith17.1K visualizações
Symfony2, creare bundle e valore per il cliente por Leonardo Proietti
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti1.3K visualizações
SOLID PRINCIPLES por Luciano Queiroz
SOLID PRINCIPLESSOLID PRINCIPLES
SOLID PRINCIPLES
Luciano Queiroz868 visualizações
Quebec pdo por Rengga Aditya
Quebec pdoQuebec pdo
Quebec pdo
Rengga Aditya463 visualizações
WordPress REST API hacking por Jeroen van Dijk
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
Jeroen van Dijk3.7K visualizações
Jsphp 110312161301-phpapp02 por Seri Moth
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
Seri Moth514 visualizações
Lithium: The Framework for People Who Hate Frameworks por Nate Abele
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
Nate Abele12.2K visualizações
Doctrine and NoSQL por Benjamin Eberlei
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
Benjamin Eberlei5.1K visualizações
関西PHP勉強会 php5.4つまみぐい por Hisateru Tanaka
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
Hisateru Tanaka2.6K visualizações

Último

Web Dev - 1 PPT.pdf por
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdfgdsczhcet
52 visualizações45 slides
The Research Portal of Catalonia: Growing more (information) & more (services) por
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
66 visualizações25 slides
"How we switched to Kanban and how it integrates with product planning", Vady... por
"How we switched to Kanban and how it integrates with product planning", Vady..."How we switched to Kanban and how it integrates with product planning", Vady...
"How we switched to Kanban and how it integrates with product planning", Vady...Fwdays
61 visualizações24 slides
MemVerge: Memory Viewer Software por
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer SoftwareCXL Forum
118 visualizações10 slides
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV por
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTVSplunk
86 visualizações20 slides
Samsung: CMM-H Tiered Memory Solution with Built-in DRAM por
Samsung: CMM-H Tiered Memory Solution with Built-in DRAMSamsung: CMM-H Tiered Memory Solution with Built-in DRAM
Samsung: CMM-H Tiered Memory Solution with Built-in DRAMCXL Forum
105 visualizações7 slides

Último(20)

Web Dev - 1 PPT.pdf por gdsczhcet
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet52 visualizações
"How we switched to Kanban and how it integrates with product planning", Vady... por Fwdays
"How we switched to Kanban and how it integrates with product planning", Vady..."How we switched to Kanban and how it integrates with product planning", Vady...
"How we switched to Kanban and how it integrates with product planning", Vady...
Fwdays61 visualizações
MemVerge: Memory Viewer Software por CXL Forum
MemVerge: Memory Viewer SoftwareMemVerge: Memory Viewer Software
MemVerge: Memory Viewer Software
CXL Forum118 visualizações
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV por Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk86 visualizações
Samsung: CMM-H Tiered Memory Solution with Built-in DRAM por CXL Forum
Samsung: CMM-H Tiered Memory Solution with Built-in DRAMSamsung: CMM-H Tiered Memory Solution with Built-in DRAM
Samsung: CMM-H Tiered Memory Solution with Built-in DRAM
CXL Forum105 visualizações
Future of Learning - Yap Aye Wee.pdf por NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS38 visualizações
ChatGPT and AI for Web Developers por Maximiliano Firtman
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman174 visualizações
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen... por NUS-ISS
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
Upskilling the Evolving Workforce with Digital Fluency for Tomorrow's Challen...
NUS-ISS23 visualizações
Five Things You SHOULD Know About Postman por Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman25 visualizações
Business Analyst Series 2023 - Week 3 Session 5 por DianaGray10
Business Analyst Series 2023 -  Week 3 Session 5Business Analyst Series 2023 -  Week 3 Session 5
Business Analyst Series 2023 - Week 3 Session 5
DianaGray10165 visualizações
PharoJS - Zürich Smalltalk Group Meetup November 2023 por Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi113 visualizações
Combining Orchestration and Choreography for a Clean Architecture por ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs168 visualizações
"Fast Start to Building on AWS", Igor Ivaniuk por Fwdays
"Fast Start to Building on AWS", Igor Ivaniuk"Fast Start to Building on AWS", Igor Ivaniuk
"Fast Start to Building on AWS", Igor Ivaniuk
Fwdays36 visualizações
"AI Startup Growth from Idea to 1M ARR", Oleksandr Uspenskyi por Fwdays
"AI Startup Growth from Idea to 1M ARR", Oleksandr Uspenskyi"AI Startup Growth from Idea to 1M ARR", Oleksandr Uspenskyi
"AI Startup Growth from Idea to 1M ARR", Oleksandr Uspenskyi
Fwdays26 visualizações
The Importance of Cybersecurity for Digital Transformation por NUS-ISS
The Importance of Cybersecurity for Digital TransformationThe Importance of Cybersecurity for Digital Transformation
The Importance of Cybersecurity for Digital Transformation
NUS-ISS25 visualizações
The details of description: Techniques, tips, and tangents on alternative tex... por BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada110 visualizações
.conf Go 2023 - Data analysis as a routine por Splunk
.conf Go 2023 - Data analysis as a routine.conf Go 2023 - Data analysis as a routine
.conf Go 2023 - Data analysis as a routine
Splunk90 visualizações
Microchip: CXL Use Cases and Enabling Ecosystem por CXL Forum
Microchip: CXL Use Cases and Enabling EcosystemMicrochip: CXL Use Cases and Enabling Ecosystem
Microchip: CXL Use Cases and Enabling Ecosystem
CXL Forum129 visualizações
"Quality Assurance: Achieving Excellence in startup without a Dedicated QA", ... por Fwdays
"Quality Assurance: Achieving Excellence in startup without a Dedicated QA", ..."Quality Assurance: Achieving Excellence in startup without a Dedicated QA", ...
"Quality Assurance: Achieving Excellence in startup without a Dedicated QA", ...
Fwdays33 visualizações

Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance

  • 1. MAGENTO 2 LAYOUT AND CODE COMPILATION FOR PERFORMANCE   by Ivan Chepurnyi
  • 4. WHAT MAKES THEM COMPLEX?
  • 5. REPEATED DATA PROCESSING // ... some xml/json/yaml file initialization foreach ($loadedData as $item) { $this->process($item); }
  • 6. NESTED LOOPS foreach ($data as $item) { $row = []; foreach ($columns as $column) { $row[] = $column->export($item); } $csv->write($row); }
  • 7. COMPLEX DEPENDENCY TREE class ClassOne { public function __construct(ClassTwo $dependency) {} } class ClassTwo { public function __construct(ClassThree $dependency) {} } class ClassThree { public function __construct(ClassFour $dependencyOne, ClassFive $dependen } // ..
  • 8. HOW CAN WE SOLVE IT?
  • 9. REPEATED DATA PROCESSING Translate your XML/JSON/YAML file into executable PHP code and include it when you need processed structure
  • 10. NESTED LOOPS Pre-compile second loop and execute it within the main one
  • 11. COMPLEX DEPENDENCY TREE Resolve dependencies and compile resolution into executable code
  • 12. BUT COMPILATION LOOKS UGLY... You need to create PHP code within PHP code You need to write it to external file You need to include that file inside of your code
  • 13. I WAS LOOKING FOR A LIBRARY Didn't find one... So I wrote it myself.
  • 14. ECOMDEVCOMPILER Created to wrap writing PHP code within PHP Automatically stores compiled code Automatically validates source and re-compiles code when needed Provides easy to use API to create parsers, builders and executors
  • 15. INSTALLATION 1. Available as a composer dependency 2. Instantiate it directly or via DI container. composer require "ecomdev/compiler"
  • 18. XML FILE <objects> <item id="object_one" type="object" /> <item id="object_two" type="object" /> <item id="object_three" type="object" /> <type id="object" class="SomeClassName"/> </objects>
  • 19. PARSER use EcomDevCompilerStatementBuilder; class Parser implements EcomDevCompilerParserInterface { // .. constructor with builder as dependency public function parse($value) { $xml = simplexml_load_string($value); $info = $this->readXml($xml); return $this->getPhpCode($info, $this->builder); } // .. other methods }
  • 20. PARSE XML DATA private function readXml($xml) { $info = []; foreach ($xml->children() as $node) { if ($node->getName() === 'type') { $info['types'][(string)$node->id] = (string)$node->class; } elseif ($node->getName() === 'object') { $info['objects'][(string)$node->id] = (string)$node->type; } } return $info; }
  • 21. CREATE PHP CODE private function getPhpCode($info, $builder) { $compiledArray = []; foreach ($info['objects'] as $objectId => $type) { $compiledArray[$objectId] = $builder->instance($info['types'][ } return $builder->container( $builder->returnValue($compiledArray) ); }
  • 22. COMPILED PHP FILE return [ 'object_one' => new SomeClassName(), 'object_two' => new SomeClassName(), 'object_three' => new SomeClassName() ];
  • 24. YOUR CONSTRUCTOR public function __construct( EcomDevCompilerBuilder $builder, EcomDevCompilerCompiler $compiler) { $this->builder = $builder; $this->compiler = $compiler; }
  • 25. EXPORT METHOD public function export($data, $columns) { $statements = $this->compileColumns($columns, $this->builder); $source = new EcomDevCompilerSourceStaticData( 'your_id', 'your_checksum', $statements ); $reference = $this->compiler->compile($source); $closure = $this->compiler->interpret($reference); foreach ($data as $item) { $row = $closure($item, $columns); } }
  • 26. COMPILATION METHOD public function compileColumns($columns, $builder) { $item = $builder->variable('item'); $compiledArray = []; foreach ($columns as $id => $column) { $compiledArray[] = $builder->chainVariable('columns')[$id] ->export($item); } $closure = $builder->closure( [$item, $builder->variable('columns')], $builder->container([$builder->returnValue($compiledArray)]) ); return $builder->container([$builder->returnValue($closure)]); }
  • 27. RESULT return function ($item, $columns) { return [ $columns['id1']->export($item), $columns['id2']->export($item), $columns['id3']->export($item), // ... ]; };
  • 28. MAIN COMPONENTS CompilerInterface - Compiler instance StorageInterface - Stores compiled files SourceInterface - Provider of data (File, String, StaticData) ParserInterface - Parser of data ObjectBuilderInterface - Bound builder for included files
  • 29. AND SOME SWEET STUFF...
  • 30. EXPORTABLE OBJECTS class SomeClass implements EcomDevCompilerExportableInterface { public function __construct($foo, $bar) { /* */ } public function export() { return [ 'foo' => $this->foo, 'bar' => $this->bar ]; } } Will be automatically compiled into: new SomeClass('fooValue', 'barValue');
  • 32. WHY? BECAUSE OF ITS ALGORITHM
  • 33. LAYOUT CACHING Every handle that is added to the MagentoFrameworkViewResult changes the cache key for the whole generated structure.
  • 34. LAYOUT GENERATION Scheduled structure is generated from XML object at all times
  • 35. SOLUTION 1. Make every handle a compiled php code 2. Include compiled handles at loading phase
  • 36. GOOD NEWS I am already working on it Will be release in April 2016
  • 37. GITHUB COMPILER LIBRARY FOR M2 https://github.com/EcomDev/compiler LAYOUT COMPILER FOR M1 https://github.com/EcomDev/EcomDev_LayoutCompiler LAYOUT COMPILER FOR M2 Coming soon