Slide 1

Slide 1 text

Debugging Performance The Right Way! https://2018.ahmedabad.wordcamp.org/

Slide 2

Slide 2 text

Dhaval Shah Founder at Mindmantra Digital A digital wrangler who loves web and WordPress just like you. #WCAHMEDABAD

Slide 3

Slide 3 text

SPEED ≠ Performance

Slide 4

Slide 4 text

Performance is the experience that you provide to your end- users!

Slide 5

Slide 5 text

While optimizing, we expect this scenario...

Slide 6

Slide 6 text

At worst this..

Slide 7

Slide 7 text

But get this!

Slide 8

Slide 8 text

Performance optimization is a continuous process

Slide 9

Slide 9 text

Performance optimization needs constant monitoring

Slide 10

Slide 10 text

Start with website analytics!

Slide 11

Slide 11 text

Which metrics to analyze? ➔ Which are the regions from where your users are coming? ➔ Which browsers they use? ➔ What kind of devices they are using? ➔ How is your bounce rate vs dwell time across the site? ➔ Is there any bounce rate correlated to specific region, browser, or device? ➔ Are there specific pages / sections where user abandons an action? ➔ Site speed analytics

Slide 12

Slide 12 text

Uptime and Performance Monitoring Tools ( use in combination with Google Analytics ) ➔ updown.io (uptime monitoring) ➔ Pingdom (uptime and performance monitoring) ➔ Uptime Robot (uptime monitoring) ➔ StatusCake (uptime and performance monitoring) ➔ ManageWP (uptime and performance monitoring)

Slide 13

Slide 13 text

Use Data to plan, execute, and analyze

Slide 14

Slide 14 text

Tools to start with.. ➔ WebPageTest.org ➔ GTMetrics ➔ Pingdom Tools ➔ PageSpeedInsights ➔ Google Lighthouse

Slide 15

Slide 15 text

Key metrics https://sites.google.com/a/webpagetest.org/docs/using-webpagetest/metrics

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Key factors affecting connection performance... ➔ DNS resolution delay ➔ Network latency ➔ Not using HTTP/2 ➔ SSL handshake ➔ No / Bad Browser Caching

Slide 18

Slide 18 text

How to optimize for them? ➔ Use a better / premium DNS ➔ Prefetch DNS / Preconnect ➔ Host near your target audience ➔ Use HTTP/2 with nginx ➔ Configure OCSP stapling for SSL ➔ Implement browser caching with gzip compression https://www.keycdn.com/blog/latency-optimization https://www.igvita.com/2015/08/17/eliminating-roundtrips-with-preconnect/ https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Key issues affecting page render ➔ Too external resources ➔ Render blocking CSS and Javascript ➔ Unoptimized Animations (both CSS & JS) ➔ Web fonts ➔ Unoptimized images

Slide 21

Slide 21 text

How to resolve them ➔ Limit external resources ➔ Inline critical CSS ➔ Defer and lazy load additional CSS ➔ Use async Javascript ➔ Use only subset of font (Weight, Language, Variant) ➔ Optimize images and lazy load https://kinsta.com/blog/critical-rendering-path/ https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp https://in.udacity.com/course/website-performance-optimization--ud884 https://in.udacity.com/course/browser-rendering-optimization--ud860

Slide 22

Slide 22 text

Optimized front-end

Slide 23

Slide 23 text

What about server side?

Slide 24

Slide 24 text

First determine which pages are critical Pages with highest traffic vs bounce rates, pages with high server response times

Slide 25

Slide 25 text

Server Logs to Rescue nginx.conf log_format extensive '$host ' '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent ' '"$http_referer" "$http_user_agent" ' '$upstream_cache_status - ' '$request_time'; https://docs.nginx.com/nginx/admin-guide/monitoring/logging/ https://dzone.com/articles/using-nginx-logging-for-application-performance-mo

Slide 26

Slide 26 text

Analyzing Logs https://goaccess.io/features

Slide 27

Slide 27 text

Finding slow code

Slide 28

Slide 28 text

QueryMonitor Plugin

Slide 29

Slide 29 text

QueryMonitor Plugin - Queries

Slide 30

Slide 30 text

QueryMonitor Plugin - Queries by Component

Slide 31

Slide 31 text

QueryMonitor with Debug Bar Slow Actions Plugin

Slide 32

Slide 32 text

WP-CLI to loop through plugins for p in $(wp plugin list --fields=name --status=active -- format=csv) do echo $p wp plugin deactivate $p for i in {1..5} do curl -so /dev/null -w "%{time_total}\n" \ -H "Pragma: no-cache" $(wp option get home) done wp plugin activate $p done https://wordpress.tv/2018/03/28/otto-kekalainen-improving-wordpress-performance-with- xdebug-and-php-profiling-2/

Slide 33

Slide 33 text

WP-CLI Profile Command wp-cli profile -wp profile stage --allow-root https://github.com/wp-cli/profile-command https://guides.wp-bullet.com/using-wp-cli-wp-profile-to-diagnose-wordpress- performance-issues/

Slide 34

Slide 34 text

WP-CLI Profile Command wp profile stage bootstrap --fields=hook,time,cache_ratio -- spotlight

Slide 35

Slide 35 text

PHP Code Profiling ● Xdebug with webgrind (never in production) ● XHProf ● New Relic (Paid APM) ● Blackfire (Paid* APM) * available for free for local development environments

Slide 36

Slide 36 text

PHP Code Profiling - Code Graphs Hot Paths Most Intensive Nodes (functions) https://deliciousbrains.com/finding-bottlenecks-wordpress- code/ https://wordpress.tv/2018/03/28/otto-kekalainen- improving-wordpress-performance-with-xdebug-and-php- profiling-2/

Slide 37

Slide 37 text

PHP Code Profiling - Code Graphs https://wordpress.tv/2018/03/28/otto-kekalainen-improving-wordpress-performance-with- xdebug-and-php-profiling-2/

Slide 38

Slide 38 text

What we did not cover? (because they need their own talks) ● Database optimization ● Cache Debugging ● Performance Budget ● Performance Driven Development

Slide 39

Slide 39 text

Key Takeaways ● Performance is continuous process ● Constantly Monitor For Performance ● Plan Optimization based on data, not by hunch ● Performance is part of development not an afterthought.

Slide 40

Slide 40 text

Dhaval Shah www.mindmantradigital.com [email protected] @dhavalgshah