# 2024년 6월 13일 작업일지

### `@swc/core`@`v1.5.29` 배포

* [커밋](https://github.com/swc-project/swc/commit/4ecda3851c9b31d14a623a325a97ffd9af9b4922)
    

나이틀리로 배포 관련 버그가 고쳐진 걸 확인돼서 정식 버전 하나 배포했다.

### 터보팩 Scope Hoisting

* [https://github.com/vercel/turbo/pull/8271](https://github.com/vercel/turbo/pull/8271)
    

웹팩에서 테스트를 베껴오려 삽질을 좀 했는데, 웹팩에 쓸만한 테스트가 없어서 결국 `git reset --hard`를 했다.

### 터보팩 Tree Shaking PR Split

* [https://github.com/vercel/turbo/pull/8472](https://github.com/vercel/turbo/pull/8472)
    

기존 PR의 요구사항이 2개인데 더 중요한 부분은 끝났고, 덜 중요한 부분은 오래 걸릴 느낌이라서 PR을 쪼갰다.

### SWC 소스맵 관련 이슈 디버깅

* [https://github.com/swc-project/swc/issues/8789](https://github.com/swc-project/swc/issues/8789)
    

`cargo` 의존성 링크하고 `yarn`으로 reproduction까지 링크해서 디버깅하기 위한 환경을 마련했다.

```bash
cls && yarn build:dev && (cd repro-swc-8789 && yarn run build)
```

이 명령어를 실행하면 패치된 로컬 러스트 코드로 repro의 `build` 스크립트를 실행한다. 근데 디버깅해보니까 입력값이 잘못된 것이었다.

### `next.js`: SWC Minifier + ESM 허용

* [https://github.com/vercel/next.js/pull/66817](https://github.com/vercel/next.js/pull/66817)
    

[swc#9026](https://github.com/swc-project/swc/pull/9026) 이 이 이슈를 고치기 위한 PR이다.

### 터보팩 Tree Shaking 최적화

* [https://github.com/vercel/turbo/pull/8473](https://github.com/vercel/turbo/pull/8473)
    

최적화 대상 입력값은

```bash
let x = 1;
x = 2;
x = 3;
x = 4;
x = 5;
x += 6;
x += 7;
x += 8;
x += 9;

export { x };

export const y = x;
```

였다. 디버깅해보니까

```bash
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:439:17] ix = 11
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:439:17] id = ItemId(Export(("x", #2), "x"))
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:439:17] "group" = "group"
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:439:17] ix = 12
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:439:17] id = ItemId(Export(("y", #2), "y"))
```

`export x` 와 `export y`가 각각 그룹을 만드는데,

```bash
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] ix = 7
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] id = ItemId(7, Normal)
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] count = 2
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] global_done.iter().filter(|&&staring_point|
            {
                has_path_connecting(&self.g.idx_graph, staring_point, ix as _,
                    None)
            }).collect::<Vec<_>>() = [
    12,
    11,
]
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] ix = 8
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] id = ItemId(8, Normal)
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] count = 2
[crates/turbopack-ecmascript/src/tree_shake/graph.rs:485:13] global_done.iter().filter(|&&staring_point|
            {
                has_path_connecting(&self.g.idx_graph, staring_point, ix as _,
                    None)
            }).collect::<Vec<_>>() = [
    12,
    11,
]
```

x, y가 둘 다 `x += 6` 같은 것들에 의존하는 것으로 처리되어서 각각 그룹이 되는 것이었다. 원래는 시작점 중에 현재 노드까지 올 수 있는 것의 개수만 체크했는데, 현재 노드에 직접적으로 의존하는 노드 개수도 체크하면 해결될 것 같아서 해봤더니 잘 작동했다.

### `next.js` 데코레이터 PR 테스트 수정

* [https://github.com/vercel/next.js/pull/65963](https://github.com/vercel/next.js/pull/65963)
    

아주 간단한 것에서 실수를 해서 빠르게 고쳤다.

### 터보팩 Tree Shaking 직관성 개선

* [https://github.com/vercel/turbo/pull/8420](https://github.com/vercel/turbo/pull/8420)
    

디버깅을 열심히 해보니 `EsmModuleItem` 의 visitor가 임포트를 조용히 없애고 있었다.

### SWC 파서 벤치마크 추가

* [https://github.com/swc-project/swc/pull/9044](https://github.com/swc-project/swc/pull/9044)
    

`oxc`하고 swc의 파서 성능 차이가 좀 나길래 이유 알아보려고 벤치마크 추가했다. AST 설계 특성상 성능 차이가 날 수밖에 없긴한데 내 생각보다 더 차이나서...
