Magento 2 CE/EE and Shopware 6 lines of code analytics

Source lines of code (SLOC), also known as lines of code (LOC), is a software metric used to measure the size of a computer program by counting the number of lines in the text of the program’s source code. SLOC is typically used to predict the amount of effort that will be required to develop a program, as well as to estimate programming productivity or maintainability once the software is produced.

SLOC measures are somewhat controversial, particularly in the way that they are sometimes misused. Experiments have repeatedly confirmed that effort is highly correlated with SLOC, that is, programs with larger SLOC values take more time to develop. Thus, SLOC can be effective in estimating effort.

More code is not necessarily better.

As an example, let’s compare different windows releases

Image for post
Image for post

In fact, even being “highly productive” (generating lots of code) is not necessarily the best outcome for a project (“if I had more time I would have written a shorter letter”)…

The teams had written a massive amount of code. Unfortunately, when you are building a complex system and running without clear constraints and delivery deadlines, the right mental image for a team that is generating lots of code is not one that is building a railroad and is now 90% across the country. A better image is one where you have dug an incredibly deep hole that you now have to figure out how to climb out of and fill back in. The team was just coming to grips with understanding all the implications of trying to ship OS features on top of this managed infrastructure. They recognized they had a ton of work to do to even make the basic premise a reality. On top of this, none of the major components were anywhere near ready to ship. They also started to realize the performance implications of introducing major new subsystems into existing code paths.

https://hackernoon.com/what-really-happened-with-vista-4ca7ffb5a1a

On June 14, 2006, one of the Windows developers Philip Su posted a blog entry which decried the development process of Windows Vista, stating that

The code is way too complicated, and that the pace of coding has been tremendously slowed down by overbearing process.

The same post also described :

Vista is said to have over 50 million lines of code, whereas XP was said to have around 40 million. (see image abovr)There are about two thousand software developers in Windows today. Assuming there are 5 years between when XP shipped and when Vista ships, those quick on the draw with calculators will discover that, on average, the typical Windows developer has produced one thousand new lines of shipped code per year during Vista. Only a thousand lines a year. […] realize that the average software developer in the US only produces around (brace yourself) 6200 lines a year. So Windows is in bad shape — but only by a constant, not by an order of magnitude.

During a demonstration of the speech recognition feature new to Windows Vista at Microsoft’s Financial Analyst Meeting on July 27, 2006, the software recognized the phrase “Dear mom” as “Dear aunt”. After several failed attempts to correct the error, the sentence eventually became “Dear aunt, let’s set so double the killer delete select all”. The richest software company in history can’t manage code.

Magento 2 is Windows Vista of the eCommerce world

Image for post
Image for post
Image provided by the Magento community: Gabor Imre

Vista and Magento 2 is too slow

For years Microsoft has been criticized by developers and IT professionals for “software bloat” — adding so many changes and features to its programs that the code gets huge and unwieldy. However, this never seemed to have enough of an effect to impact software sales. With Windows Vista, software bloat appears to have finally caught up with Microsoft.

Vista has over 50 million lines of code. XP had 35 million when it was released, and since then it has grown to about 40 million. This software bloat has had the effect of slowing down Windows Vista, especially when it’s running on anything but the latest and fastest hardware. Even then, the latest version of Windows XP soundly outperforms the latest version of Microsoft Vista. No one wants to use a new computer that is slower than their old one.

As I wrote earlier about the M2 project:

Failure is a prerequisite to invention. You can’t develop a breakthrough product or process if it’s not willing to encourage risk-taking and learn from mistakes. The growing acceptance of failure is changing the way companies approach innovation. Magento 2 project should accept failure learns from mistakes and start to build Adobe Commerce 3. I hope this process has started.

Rich Skrenta writes that code is our enemy.

Code is bad. It rots. It requires periodic maintenance. It has bugs that need to be found. New features mean old code has to be adapted. The more code you have, the more places there are for bugs to hide. The longer checkouts or compiles take. The longer it takes a new employee to make sense of your system. If you have to refactor there’s more stuff to move around.

Code is produced by engineers. To make more code requires more engineers. Engineers have n² communication costs, and all that code they add to the system, while expanding its capability, also increases a whole basket of costs. You should do whatever possible to increase the productivity of individual programmers in terms of the expressive power of the code they write. Less code to do the same thing (and possibly better). Less programmers to hire. Less organizational communication costs.

That’s why better to use small serverless Microservices instead of monolithic Magento. They are doing only necessary stuff and has fewer lines of code (1000–2000 per feature)

Less actual code is always better than more. The more stuff your code does, the more failure points there are. The more stuff your code does, the less factorable it is. The more stuff your code does, the harder it is to debug and to unit test. The more stuff your code does, the longer it takes to write! So if you can accomplish the same task by doing less stuff, that’s better than if you do more stuff.

For the test, I have used cloc open-source tool (https://github.com/AlDanial/cloc)

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

Installing SLOC

Including this instruction in case if you want to recheck the data.

Install sloc from npm, a command line tool (Node.js needs to be installed).

npm install sloc -g

Clone shallow repository (faster download than full clone).

git clone https://github.com/facebook/react/

Run sloc and specify the path that should be analyzed.

sloc “.\react\src”

sloc supports formatting the output as a cli-table, as json or csv. Regular expressions can be used to exclude files and folders (Further information on npm).

Latest release: v1.84 (September 22, 2019)

Files:

PHP:(aw, ctp, phakefile, php, php3, php4, php5, php_cs, php_cs.dist, phps, phpt, phtml)JavaScript:(_js, bones, es6, jake, jakefile, js, jsb, jscad, jsfl, jsm, jss, mjs, njs, pac, sjs, ssjs, xsjs, xsjslib)XML:(adml, admx, ant, app.config, axml, builds, ccproj, ccxml, classpath, clixml, cproject, cscfg, csdef, csl, ct, depproj, ditamap, ditaval, dll.config, dotsettings, filters, fsproj, gmx, grxml, iml, ivy, jelly, jsproj, kml, launch, mdpolicy, mjml, natvis, ndproj, nproj, nuget.config, nuspec, odd, osm, packages.config, pkgproj, plist, proj, project, props, ps1xml, psc1, pt, rdf, resx, rss, scxml, settings.stylecop, sfproj, shproj, srdf, storyboard, sttheme, sublime-snippet, targets, tmcommand, tml, tmlanguage, tmpreferences, tmsnippet, tmtheme, urdf, ux, vcxproj, vsixmanifest, vssettings, vstemplate, vxml, web.config, web.debug.config, web.release.config, wsf, x3d, xacro, xib, xlf, xliff, XML, xml, xml.dist, xproj, xspec, xul, zcml)HTML:(htm, html, html.hl, xht)

Legend:

blank lines = original — non_blank

comment lines = non_blank — code

code lines = code

Magento 2

Magento 2 CE 2.3.x

exclude-dir: cache,test,generated,var

Image for post
Image for post
Magento 2 CE cloc metrics output
+------------+-------+---------+
| Language | files | code |
+------------+-------+---------+
| PHP | 47060 | 3245229 |
+------------+-------+---------+
| XML | 10695 | 1021527 |
+------------+-------+---------+
| JavaScript | 2421 | 458303 |
+------------+-------+---------+
| Markdown | 1292 | 110875 |
+------------+-------+---------+
| JSON | 835 | 94887 |
+------------+-------+---------+
| CSS | 348 | 83393 |
+------------+-------+---------+
| LESS | 624 | 74117 |
+------------+-------+---------+
| HTML | 589 | 61123 |
+------------+-------+---------+
| XSD | 224 | 19209 |
+------------+-------+---------+

Just Vandor/Magento folder:

Image for post
Image for post
+------------+-------+---------+
| Language | files | code |
+------------+-------+---------+
| PHP | 19971 | 1362044 |
+------------+-------+---------+
| XML | 6015 | 822084 |
+------------+-------+---------+
| JavaScript | 1320 | 235288 |
+------------+-------+---------+
| LESS | 487 | 62059 |
+------------+-------+---------+
| HTML | 424 | 33158 |
+------------+-------+---------+
| JSON | 327 | 22634 |
+------------+-------+---------+
| CSS | 99 | 19547 |
+------------+-------+---------+
| Markdown | 486 | 16121 |
+------------+-------+---------+
| XSD | 205 | 16105 |
+------------+-------+---------+
| SVG | 34 | 4373 |
+------------+-------+---------+
| GraphQL | 30 | 1853 |
+------------+-------+---------+
Image for post
Image for post
+------------+-------+--------+
| Language | files | code |
+------------+-------+--------+
| PHP | 14484 | 824485 |
+------------+-------+--------+
| XML | 3125 | 699306 |
+------------+-------+--------+
| JavaScript | 1316 | 235275 |
+------------+-------+--------+
| LESS | 484 | 62038 |
+------------+-------+--------+
| HTML | 421 | 33073 |
+------------+-------+--------+
| JSON | 316 | 22342 |
+------------+-------+--------+
| CSS | 93 | 19507 |
+------------+-------+--------+

Magento 2.3.x EE

Image for post
Image for post
+------------+-------+---------+
| Language | files | code |
+------------+-------+---------+
| PHP | 54097 | 3632116 |
+------------+-------+---------+
| XML | 14139 | 1225833 |
+------------+-------+---------+
| JavaScript | 6111 | 1090028 |
+------------+-------+---------+
| CSS | 630 | 115109 |
+------------+-------+---------+
| JSON | 982 | 113649 |
+------------+-------+---------+
| Markdown | 1469 | 112154 |
+------------+-------+---------+
| HTML | 1713 | 97636 |
+------------+-------+---------+
| LESS | 757 | 79682 |
+------------+-------+---------+
| XSD | 237 | 20386 |
+------------+-------+---------+
Image for post
Image for post
+------------+-------+---------+
| Language | files | code |
+------------+-------+---------+
| PHP | 24296 | 1631152 |
+------------+-------+---------+
| XML | 8262 | 992890 |
+------------+-------+---------+
| JavaScript | 1686 | 267943 |
+------------+-------+---------+
| LESS | 620 | 67624 |
+------------+-------+---------+
| HTML | 572 | 36559 |
+------------+-------+---------+
| JSON | 462 | 29713 |
+------------+-------+---------+
| CSS | 103 | 19797 |
+------------+-------+---------+
| Markdown | 656 | 17314 |
+------------+-------+---------+
| XSD | 218 | 17282 |
+------------+-------+---------+
| TypeScript | 197 | 9371 |
+------------+-------+---------+
| SVG | 65 | 4655 |
+------------+-------+---------+
| GraphQL | 35 | 1974 |
+------------+-------+---------+

Excluding tests:

Image for post
Image for post
+------------+-------+--------+
| Language | files | code |
+------------+-------+--------+
| PHP | 17676 | 984271 |
+------------+-------+--------+
| XML | 4404 | 747265 |
+------------+-------+--------+
| JavaScript | 1682 | 267930 |
+------------+-------+--------+
| LESS | 617 | 67603 |
+------------+-------+--------+
| HTML | 569 | 36474 |
+------------+-------+--------+
| JSON | 451 | 29421 |
+------------+-------+--------+
| CSS | 97 | 19757 |
+------------+-------+--------+
| Markdown | 430 | 16862 |
+------------+-------+--------+
| XSD | 198 | 14180 |
+------------+-------+--------+

ShopWare 6

exclude-dir:cache,.git,test,generated,var,dev-ops

Image for post
Image for post
ShopWare 6 code complexity
+--------------+-------+---------+
| Language | files | code |
+--------------+-------+---------+
| JavaScript | 40809 | 3849510 |
+--------------+-------+---------+
| PHP | 14050 | 1086864 |
+--------------+-------+---------+
| Markdown | 6891 | 676867 |
+--------------+-------+---------+
| JSON | 5473 | 654896 |
+--------------+-------+---------+
| TypeScript | 5680 | 150481 |
+--------------+-------+---------+
| CSS | 169 | 91705 |
+--------------+-------+---------+
| Python | 161 | 60527 |
+--------------+-------+---------+
| HTML | 235 | 57843 |
+--------------+-------+---------+
| Twig | 947 | 53863 |
+--------------+-------+---------+
| XML | 817 | 52224 |
+--------------+-------+---------+
| C++ | 132 | 43310 |
+--------------+-------+---------+
| SVG | 2170 | 33248 |
+--------------+-------+---------+
| Sass | 733 | 32890 |
+--------------+-------+---------+
| C/C++ Header | 203 | 30253 |
+--------------+-------+---------+
| YAML | 1025 | 26305 |
+--------------+-------+---------+

NOTICE:

TJ Gamble noticed:

Image for post
Image for post

“A little unfair to set this entire thing up by talking about engineering costs, etc as the premise but then completely ignore the Javascript as if it doesn’t need engineers or maintenance so the numbers are more skewed in the author’s favor. I’m was looking forward to reading a fair comparison as the subject is interesting but this just a skewed hit piece.”

In current installation Shopware has more JS files because of node_modules in vendor/shopware/administration/Resources/node_modules/ and vendor/shopware/storefront/Resources/app/storefront/node_modules/ folders. After removing npm modules JS count decreases. Node Modules is not an executable backend code, it is a deployment tool.

Also, the Shopware core folder included and counts twice.

Image for post
Image for post
Shopware JS Counts without NPM modules and

Anyway in this test we counting only backend PHP code and it doesn’t affect Magento results. It plays into the hands of Magento 2. JS count it is topic or another post and I don’t have clear undersending how to count (with node_modules or just pub/static folder)

Just platform folder or /vendor/shopware/platform/:

Image for post
Image for post
+--------------+-------+---------+
| Language | files | code |
+--------------+-------+---------+
| JavaScript | 40744 | 3838280 |
+--------------+-------+---------+
| Markdown | 6386 | 645084 |
+--------------+-------+---------+
| JSON | 5107 | 608025 |
+--------------+-------+---------+
| PHP | 3032 | 223044 |
+--------------+-------+---------+
| TypeScript | 5680 | 150481 |
+--------------+-------+---------+
| Python | 160 | 60508 |
+--------------+-------+---------+
| HTML | 213 | 52016 |
+--------------+-------+---------+
| Twig | 826 | 44299 |
+--------------+-------+---------+
| C++ | 132 | 43310 |
+--------------+-------+---------+
| CSS | 105 | 39518 |
+--------------+-------+---------+
| Sass | 729 | 32827 |
+--------------+-------+---------+
| C/C++ Header | 202 | 30228 |
+--------------+-------+---------+
| SVG | 780 | 26043 |
+--------------+-------+---------+
| YAML | 597 | 18278 |
+--------------+-------+---------+
| XML | 141 | 17644 |
+--------------+-------+---------+
Image for post
Image for post
+------------+-------+--------+---------+---------+
| Language | files | blank | comment | code |
+------------+-------+--------+---------+---------+
| JavaScript | 40744 | 661983 | 793984 | 3838280 |
+------------+-------+--------+---------+---------+
| Markdown | 6376 | 272512 | 12 | 643893 |
+------------+-------+--------+---------+---------+
| JSON | 5095 | 4318 | 0 | 607616 |
+------------+-------+--------+---------+---------+
| TypeScript | 5680 | 18641 | 99365 | 150481 |
+------------+-------+--------+---------+---------+
| PHP | 2374 | 34140 | 23685 | 135309 |
+------------+-------+--------+---------+---------+

Sorry forget to add these files — Twig 44235

Shopware has more Java Scrip but in our case, we are comparing only

Pivot results:

Magento 2.3 CE PHP core code lines without composer dependencies = 824 485 lines not including 699 306 XML configuration lines and PHP Tests

Magento 2.3 EE PHP core code lines without composer dependencies = 984 271 lines not including 747 265 XML configuration lines and PHP Tests

Shopware 6 core code lines without composer dependencies = 135 309 lines of code + 44 235 Twig files = 179 544 lines of code Not including 17 861 YAML configurations and 17 318 XML files

Image for post
Image for post

With the generated folder. The generated folder has additional 1 726 665 for CE and code lines 1 577 034 for EE. OMG!

Image for post
Image for post

Magento 2.3 CE PHP code with composer dependencies = 3 245 229

Magento 2.3 EE PHP core code lines without composer dependencies = 3 632 116

Shopware 6 = 1 086 864 lines of code + 44 299 Twig files = 1 131 163

I found Shopware has a platform folder twice, but it’s ok it doesn’t change much.

Image for post
Image for post
+--------------+---------+--------+
| PHP | Full | Core |
+--------------+---------+--------+
| Magento 2 CE | 3245229 | 824485 |
+--------------+---------+--------+
| Magento 2 EE | 3632116 | 984271 |
+--------------+---------+--------+
| ShopWare 6 | 1131163 | 179544 |
+--------------+---------+--------+

Overall Magento CE Installation:

Image for post
Image for post

Overall Magento EE Installation:

Image for post
Image for post

Overall ShopWare Installation:

Image for post
Image for post
Image for post
Image for post

End we even don’t count JS file 1M+

5M lines of code it is 90 000 pages of printed text, War and Peace x 70, Ulysses x 125, The Catcher in The Rye x 315

So, Magento 2 depends on how to count (with vendor folder or without) located somewhere between there:

  • Large Hadron Collider
  • Linux Kernel 2.2.0
  • Photoshop CS 6
  • Unreal Engine 3
  • Age of Empire Online
Image for post
Image for post

Another problem, not one of these systems is not written on pure performance programing language like PHP …

Image for post
Image for post
Image for post
Image for post

WooComeerce + Wordpress lines of code:

Image for post
Image for post

Silius lines of code:

Image for post
Image for post

Open cart :

Image for post
Image for post

Zen Cart:

Image for post
Image for post

Presta Shop:

Image for post
Image for post

ShopWare 5 :

Image for post
Image for post

Just Core without composer dependencies:

Image for post
Image for post

ShopWare is a great example of how a new better version of the software can contain fewer code lines:

Image for post
Image for post
ShopWare 5 vs SW 6 lines of code including tests

Excluding tests, SW5 has: 273 470 lines of code SW 6 179 544

The popularity of the eCommerce platform over time:

Image for post
Image for post

Let’s compare eCommerce, not on PHP

We know what PHP is not so popular nowadays. It lives mostly because of legacy WordPress/Joomla/Drupal/Magento1.

Image for post
Image for post
Programming Languages (PHP, Python, JavaScript) Popularity

The popularity of programming technologies in the modern tech stack:

Image for post
Image for post

Saleor:

To be continued…

Read Also: Magento 2 is 2 times slower than M1:

Written by

Magento/APP Cloud Architect. Melting metal server infrastructure into cloud solutions.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store