Technique to delete unused codes

Ecc0bdbe7abfdc4fe2fd6be5621f1bcd?s=47 Naoto Sato
January 26, 2019

Technique to delete unused codes

Ecc0bdbe7abfdc4fe2fd6be5621f1bcd?s=128

Naoto Sato

January 26, 2019
Tweet

Transcript

  1. コードを削除する技術 Technique to delete unused codes PHP Conference Sendai 2019

    @naopr
  2. @naopr • Backend Engineer at Mercari, Inc. • Tech Lead

    of CSTool Team • Love
  3. Relationship between Mercari & Sendai Sendai Reply to inquiries Monitor

    contents Fukuoka Call-center Tokyo Head Office Develop apps
  4. Relationship between Mercari & PHP • Mercari app’s API is

    written in PHP • Migrating to microservices ◦ From PHP to Go ◦ Break down existing API into multiple services ◦ MTC2018 - Mercari API: from Monolithic to Microservices
  5. Technique to delete unused codes

  6. Agenda • Why do we need to delete unused codes?

    • Mercari’s case ◦ How to delete unused codes ◦ Result • Conclusion
  7. Why do we need to delete unused codes? • Reduce

    development costs ◦ Reading cost ◦ Updating cost • Speed up the system ◦ Response time ◦ CI
  8. How to delete unused codes Detect unused APIs Build project

    team Delete codes 1 2 3
  9. Detect unused APIs 1. List APIs that haven’t been recently

    accessed a. For a month in our case b. Use Google BigQuery & a script written in Go 2. Check if we may delete the API a. Investigate codes b. Use `git blame` and ask implementer c. Find tickets related to it
  10. Make API list by spreadsheet

  11. Build project team • Collect fellows [Important] ◦ backend engineer

    ◦ QA engineer • Decide the release procedure ◦ How to do QA ◦ JIRA ticket • Hold a kick-off with ◦ Better to hold it every month
  12. Delete codes • Check recent access log • Check methods

    recursively ◦ Type and type `git grep`! ◦ With symbol search function by PhpStorm ◦ Controller, Service, Exception, Entity, DB table, DB schema, test, etc...
  13. Result

  14. Result summary • Deleted 349 / 370 (≒94%) unused APIs

    ◦ In 3 months ◦ 7 backend engineers + 1 frontend engineers ◦ About 80k〜100k lines • Reverted 9 PRs ◦ Other repositories were affected when tables were dropped ◦ Forgot to check the access log
  15. Conclusion

  16. Deleting code is difficult • Need to read the code

    steadily or ask a senior engineer • Do it with fellows, NOT alone • Don’t forget to check the access log • Check the impact on other repositories when drop tables • Let’s hold a drinking party every month
  17. Let’s delete codes! and drink