I know to refactor my commits only based on previous review comments. I code and test it thoroughly most of the time, but it's hard for me to identify places to refactor. How to get good at refactoring or even identifying places to refactor?
I follow a rough playbook of:
Usually I start my search of things to refactor at very large, legacy modules or modules under my ownership. After around a year or two of refactoring code and writing code from scratch for new products, things just clicked for me (likely from having a stronger subconcious understanding of what code did/didn't work and what patterns did I commonly have to end up refactoring).
Be careful that you aren't just looking for opportunities to refactor for the sake of refactoring. There can be so many opportunities to refactor different parts of the code base, but you have to make the calculation of whether it's a worthwhile place to refactor. If you are finding it hard to identify places to refactor, I would hold off until you're more familiar with the codebase.
A good signal that you should refactor is that you and other engineers have a loss of productivity when building in a certain part of the code. If you get a sense of anxiety when touching a certain part of the code, you can probably add it as a candidate as a place where you can refactor the code. You should be having regular 1:1s with people from your team and people on other teams, and you can gauge where frustration in a codebase lies.
Find some guiding principles and how to balance them.
Also remember, the more experience you get the more you can think of simplifying the process.
Something that can help for small wins are:
For more in-depth: