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. コードを削除する技術
    Technique to delete unused codes
    PHP Conference Sendai 2019
    @naopr

    View Slide

  2. @naopr
    ● Backend Engineer at Mercari, Inc.
    ● Tech Lead of CSTool Team
    ● Love

    View Slide

  3. Relationship between Mercari & Sendai
    Sendai
    Reply to inquiries
    Monitor contents
    Fukuoka
    Call-center
    Tokyo
    Head Office
    Develop apps

    View Slide

  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

    View Slide

  5. Technique to delete
    unused codes

    View Slide

  6. Agenda
    ● Why do we need to delete unused codes?
    ● Mercari’s case
    ○ How to delete unused codes
    ○ Result
    ● Conclusion

    View Slide

  7. Why do we need to delete unused codes?
    ● Reduce development costs
    ○ Reading cost
    ○ Updating cost
    ● Speed up the system
    ○ Response time
    ○ CI

    View Slide

  8. How to delete unused codes
    Detect unused APIs
    Build project team
    Delete codes
    1
    2
    3

    View Slide

  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

    View Slide

  10. Make API list by spreadsheet

    View Slide

  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

    View Slide

  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...

    View Slide

  13. Result

    View Slide

  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

    View Slide

  15. Conclusion

    View Slide

  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

    View Slide

  17. Let’s delete codes!
    and drink

    View Slide