-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix(utils): intersection 기능 개선 및 밴치마크 추가 #311
Conversation
|
|
||
export const intersectionWithDuplicates = <T, U = T>( | ||
export const intersectionWithDuplicates = <T, U>( | ||
firstArr: T[] | readonly T[], | ||
secondArr: T[] | readonly T[], | ||
iteratee: (item: T) => T | U = identity, | ||
iteratee?: (item: T) => U | ||
) => { | ||
const secondArrSetAppliedIteratee = new Set(secondArr.map(iteratee)); | ||
|
||
return firstArr.filter((item) => | ||
secondArrSetAppliedIteratee.has(iteratee(item)), | ||
const secondArrToSet = new Set<T | U>( | ||
iteratee ? secondArr.map(iteratee) : secondArr | ||
); | ||
|
||
const filterFn = iteratee | ||
? (element: T) => secondArrToSet.has(iteratee(element)) | ||
: (element: T) => secondArrToSet.has(element); | ||
|
||
return firstArr.filter(filterFn); |
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.
iteratee를 무조건 실행하는건 불 필요합니다. identity와 같은 간단한 함수라도 매번 해당 함수를 호출하는건 성능적으로 좋지 않습니다. 따라서, iteratee 존재 여부로 이러한 처리를 분기 처리하도록 변경합니다! 🙏
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #311 +/- ##
==========================================
+ Coverage 96.37% 96.96% +0.58%
==========================================
Files 126 125 -1
Lines 1325 1318 -7
Branches 325 327 +2
==========================================
+ Hits 1277 1278 +1
+ Misses 42 34 -8
Partials 6 6
|
0aebe2c
to
4c75e19
Compare
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.
벤치마크 테스트 너무 좋네요!!
불필요한 iteratee에 대한 개선도 너무 감사합니다! 🙇 고생많으셨습니다! 👍👍👍
@Sangminnn 빠른 확인감사합니다ㅎㅎ vitest의 벤치마크 테스트 기능이 너무 좋은 것 같습니다!! 이번에 도입하면서 소개하게되어 정말 좋네요👍👍 |
Overview
fix(utils): intersection 기능 개선 및 밴치마크 추가
intersectionWithDuplicates 는 비교 대상이 없어 밴치마크 테스트 제외
benchmark
약 2배
더 빠릅니다.PR Checklist
Contributing Guide