Skip to content
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

Merged
merged 3 commits into from
Jul 7, 2024

Conversation

ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented Jul 7, 2024

Overview

fix(utils): intersection 기능 개선 및 밴치마크 추가

intersectionWithDuplicates 는 비교 대상이 없어 밴치마크 테스트 제외

benchmark

  • lodash의 intersectionBy보다 평균적으로 약 2배 더 빠릅니다.
스크린샷 2024-07-07 오후 5 48 42

PR Checklist

  • All tests pass.
  • All type checks pass.
  • I have read the Contributing Guide document.
    Contributing Guide

@ssi02014 ssi02014 requested a review from Sangminnn July 7, 2024 08:49
@ssi02014 ssi02014 self-assigned this Jul 7, 2024
Copy link

changeset-bot bot commented Jul 7, 2024

⚠️ No Changeset found

Latest commit: 4c75e19

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ssi02014 ssi02014 added @modern-kit/utils @modern-kit/utils test 테스트 코드 추가 labels Jul 7, 2024
Comment on lines -2 to +14

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iteratee를 무조건 실행하는건 불 필요합니다. identity와 같은 간단한 함수라도 매번 해당 함수를 호출하는건 성능적으로 좋지 않습니다. 따라서, iteratee 존재 여부로 이러한 처리를 분기 처리하도록 변경합니다! 🙏

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.96%. Comparing base (2aed455) to head (4c75e19).

Additional details and impacted files

Impacted file tree graph

@@            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              
Components Coverage Δ
@modern-kit/react 94.63% <ø> (ø)
@modern-kit/utils 100.00% <100.00%> (+1.38%) ⬆️

Copy link
Collaborator

@Sangminnn Sangminnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

벤치마크 테스트 너무 좋네요!!
불필요한 iteratee에 대한 개선도 너무 감사합니다! 🙇 고생많으셨습니다! 👍👍👍

@ssi02014 ssi02014 merged commit d077d2d into main Jul 7, 2024
3 checks passed
@ssi02014 ssi02014 deleted the test/intersection branch July 7, 2024 12:14
@ssi02014
Copy link
Contributor Author

ssi02014 commented Jul 7, 2024

@Sangminnn 빠른 확인감사합니다ㅎㅎ vitest의 벤치마크 테스트 기능이 너무 좋은 것 같습니다!! 이번에 도입하면서 소개하게되어 정말 좋네요👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@modern-kit/utils @modern-kit/utils test 테스트 코드 추가
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants