Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Technique to delete unused codes

Naoto Sato
January 26, 2019

Technique to delete unused codes

Naoto Sato

January 26, 2019
Tweet

More Decks by Naoto Sato

Other Decks in Technology

Transcript

  1. Relationship between Mercari & Sendai Sendai Reply to inquiries Monitor

    contents Fukuoka Call-center Tokyo Head Office Develop apps
  2. 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
  3. Agenda • Why do we need to delete unused codes?

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

    development costs ◦ Reading cost ◦ Updating cost • Speed up the system ◦ Response time ◦ CI
  5. 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
  6. 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
  7. 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...
  8. 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
  9. 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