-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] #520 - DateFormatter() 인스턴스 메모리 최적화 #528
base: develop
Are you sure you want to change the base?
Conversation
- Utils/setDateFormat 대체
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실험군들 비교해가며 인스턴스 메모리 최적화 잘 봤습니다 :)
저도 실제 성능 테스트를 하는 습관을 들여야겠어요 호호.
코드리뷰에선 날짜 변환의 책임 관련해서 리뷰 남겼습니다.
의견 남겨주세요!
SOPT-iOS/Projects/Core/Sources/Utils/DateFormatterManager.swift
Outdated
Show resolved
Hide resolved
...OS/Projects/Features/AttendanceFeature/Sources/ShowAttendanceScene/VC/ShowAttendanceVC.swift
Outdated
Show resolved
Hide resolved
extension CalendarCardCVC { | ||
func configureCell(model: HomePresentationModel.RecentSchedule, | ||
userType: UserType) { | ||
// TODO: 서버 - 날짜 포맷 변경 후 반영 | ||
self.dateLabel.text = setDateFormat(date: model.date, to: "MM.dd") | ||
self.dateLabel.text = DateFormatManager.shared.transformDateFormat(model.date, from: .monthDayWIthDash, to: .monthDayWithDot) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서버에서 받아온 날짜 관련 String을
뷰계층에서 from -> to로 바꿔주는 것이군요 :)
서버와 약속한 Date format으로 Date를 변환하는 역할은 누구에게 책임이 있다고 생각하시나요?
저는 해당 책임은 데이터 모듈 혹은 네트워크 모듈이 지녀야 한다고 생각해요.
서버의 문자열 format이 바뀌었을 때 뷰계층 코드를 변경하는 것보단 네트워크쪽 코드를 변경하는 것이 자연스럽다고 느껴지기 때문이에요
Date값이 Data계층에서 Domain계층으로 넘어갈 때 String 값을 Date값으로 변경하고,
Presentation 계층에선 Date -> String으로 변환하는 방식은 어떨까요?
Domain에는 가장 순수한 Date 타입만 존재하면 좋을 것 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다시 생각해보니 해당 PR은 메모리 성능 최적화가 중점적이라, PR에서 작업하지 않은 내용을 리뷰한 것 같네요 ㅎㅎ;
그래도 같이 고민해보면 좋을 것 같습니다 .. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리뷰 감사합니다 !! 기존 코드 수정에만 집중하다 보니 각 레이어의 역할 분리에 대해 깊이 있게 고민하지 못했던 것 같아요.
석우님 말씀처럼 서버에서 받아온 날짜(String)값
을 Data -> Domain 단계에서 Date 타입으로로 변환하면 UI 상황에 맞게 다양한 포맷으로 변경할 수 있어 더 유연한 구조가 될 것 같네요 ! 리뷰에 함께 반영하도록 하겠습니다👍👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 수용해주셔서 감사함다 :)
현 구조에선 toDomain()에서 String을 Date로 변환하는 것이 가장 편할 것 같네요.
이외에도 서버의 requestBody의 json을 Decodable 구조체로 디코딩할 때 JSONDecoder의 dateStrategyFormat값을 통해 처음부터 해당 밸류값을 Date 타입으로도 받아오는 방법도 있습니다~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
굿굿
🌴 PR 요약
🌱 작업한 브랜치
🌱 PR Point
DateFormatter()
인스턴스 초기화 비용과 함수 실행 시간에 대한 테스트를 진행했습니다. 테스트 기록테스트 결과를 요약하면 아래와 같습니다!
테스트를 통해
DateFormatter
의 초기화 비용은 다른 객체와 큰 차이가 나지 않지만 프로퍼티를 변경하거나 함수를 사용할 때 비용이 크다는 것을 알 수 있었습니다. 따라서 싱글톤으로 객체를 관리하는DateFormatManager
클래스를 생성하여 공통 인스턴스를 활용하도록 리팩토링을 진행했습니다.리팩토링 이후 전, 후의 DateFormatter 인스턴스 수를 memory graph로 확인해보았습니다.
최적화 후 인스턴스 수가 3개로 줄어들고
NetworkLoggerPlugin
이 더 이상DateFormatter
인스턴스를 참조하지 않는 것을 확인할 수 있었습니다.3개의 인스턴스 중 불필요한 객체는 없는지 마지막으로 확인해보았는데요,
memory graph로 확인했을 때3개 인스턴스는 각각
DateFormatManager
,Sentry
,Amplitude
객체에서 사용되는 것으로 확인되었습니다.+) Sentry 제거와 crashlytics 부착 작업 일정도 논의해보아요!
📌 참고 사항
NetworkLogger
를 제외한 모든 곳에서ko_KR
을 사용하고 있어NetworkLogger
도 한국시간대로 통일했습니다.DateFormatManager
가 사용된 부분은 출석뷰, 홈화면, 솝마디, 알림(알림이 얼마나 되었는지, 솝마디를 확인할 수 있는 날인지)입니다.📮 관련 이슈