Skip to content

refactor: cache CargoClassMetadata to aviod redundant construction per request#216

Open
yuchem2 wants to merge 3 commits intodevelopfrom
CARGO-400
Open

refactor: cache CargoClassMetadata to aviod redundant construction per request#216
yuchem2 wants to merge 3 commits intodevelopfrom
CARGO-400

Conversation

@yuchem2
Copy link
Copy Markdown
Member

@yuchem2 yuchem2 commented Apr 15, 2026

현재 bindingCargo 함수 내에서 사용자가 입력한 class 객체를 평가하기 위해 매 요청마다 객체를 새롭게 생성해서 사용하고 있어 이를 해결하기 위한 작업을 수행하였습니다.

처음에는 클로저 방식으로 최상위 클래스의 메타데이터만 사전 분석하였으나, 중첩 구조에서는 여전히 매 요청마다 메타데이터를 재생성하는 문제가 있어 모듈 레벨 캐시를 도입하여 모든 클래스의 메타데이터를 일관되게 캐싱하도록 변경하였습니다.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a caching mechanism for CargoClassMetadata using a Map and a helper function to optimize performance by avoiding redundant object creation during the binding process. The review feedback suggests further improving this by moving the initialization logic for the metadata state into the cache retrieval function and removing the now-redundant calls from the main binding logic.

Comment thread packages/express-cargo/src/binding.ts
Comment thread packages/express-cargo/src/binding.ts Outdated
@dami0806
Copy link
Copy Markdown
Contributor

확인했습니다! 캐싱되는 데이터가 코드에 고정된 클래스 구조라서 캐시에 대한 다른 추가 정책이 없어도 괜찮은거군요??

let meta = metaCache.get(classConstructor)
if (!meta) {
meta = new CargoClassMetadata(classConstructor.prototype)
meta.markBindingCargoCalled()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

이제 이 함수 필요 없지 않을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants