owned this note changed 5 years ago
Linked with GitHub

大象也能飛翔!聊 Laravel 效能調校

講者:趙家笙 Recca Chao

歡迎來到 LaravelConf Taiwan 2020 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

共筆入口:https://hackmd.io/@LaravelTaiwan/Conf2020
手機版請點選上方 按鈕展開議程列表。

大綱

使用 Laravel 開發之後,隨著用戶逐漸變多,覺得專案運作越來越慢,主機越架越大台,卻又不願意放棄繼續使用 Laravel 嗎?
今天我們來聊聊怎麼讓你的專案從一頭行動遲緩的大象,搖身一變成為騰雲駕霧的小飛象!

議程筆記

要先測量,才能調教效能

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Laravel 7 > 5.8 > 6

先優化資料庫和靜態資源

理解語法與框架特性,並加以利用

PHP 調教

PHP 特性: PHP 原生函式的 overhead 相對大,減少原生函式呼叫,可能會提升效能

  • loop over array

    • while: 最差,不穩定
    • foreach
    • array_keys & index & for
  • array add item

    • array_push($arr, $item)
    • $arr[] = $item; -> faster
  • 檢查 key

    • array_key_exists()
    • isset() -> faster
  • array syntax

    • array()
    • []
  • string length

    • isset($string[10])
    • strlen($string)
  • function

    • call_user_func($func)
    • $func()

Laravel 調教

  • php artisan optimize
  • 移除未使用的 ServiceProvider
  • 移除多餘 Middleware

其他

  • 橫向、縱向擴展
  • with() 改善 SQL query (eager loading)
    減少 query 次數
  • LazyCollection
  • (QA) 提升開發人力物力效能
Select a repo