perf(core): JSON 서빙 네트워크 오버헤드 최적화

실측(g7.dev) 결과 줄바꿈 제거·gzip 은 이미 적용된 상태였고,
남은 실질 개선 3종을 구현:

- 모든 API 응답에 JSON_UNESCAPED_UNICODE 적용 — 한글이 \uXXXX(6B)로
 팽창하던 것을 raw UTF-8(3B)로 직렬화 (lang pack gzip -9.1%)
- 공개 레이아웃 서빙에서 개발자용 comment/_comment 재귀 제거,
 편집 모드(with_source_meta)는 보존 (layout gzip -34.9%)
- 번들 JS/CSS(BinaryFileResponse) gzip 압축 사각지대 해소 —
 기존 미들웨어가 getContent==false 로 압축을 건너뛰던 문제 (-73~77%)
This commit is contained in:
HeuJung committed 2026-07-05 22:31:04 +09:00
1 parent a958443d69
commit c819820573
11 files changed
+638 -145

No files matched your search

+36
View File
@@ -807,6 +807,12 @@ class LayoutService
// 캐시 비활성 시 매번 병합 실행
if (! $cacheEnabled) {
$merged = $this->loadAndMergeLayoutInternal($templateId, $layoutName, $withSourceMeta);
// 공개 서빙 응답에서 개발자용 comment 필드 제거 (편집 모드는 보존)
if (! $withSourceMeta) {
$merged = $this->stripDeveloperComments($merged);
}
HookManager::doAction('core.layout.after_load', $merged, $templateId, $layoutName, false);
return $merged;
@@ -844,6 +850,12 @@ class LayoutService
// 병합된 레이아웃 생성
$mergedLayout = $this->loadAndMergeLayoutInternal($templateId, $layoutName, $withSourceMeta);
// 공개 서빙 응답에서 개발자용 comment 필드 제거 (편집 모드는 보존).
// withSourceMeta 가 캐시 키에 반영되므로 공개/편집 캐시가 분리되어 안전.
if (! $withSourceMeta) {
$mergedLayout = $this->stripDeveloperComments($mergedLayout);
}
// 캐시에 저장
$cacheTtl = $this->getCacheTtl();
$this->cache->put($cacheKey, $mergedLayout, $cacheTtl);
@@ -1601,6 +1613,30 @@ class LayoutService
}, $components);
}
/**
* 병합된 레이아웃에서 개발자용 comment 필드를 재귀적으로 제거합니다.
*
* 레이아웃 JSON 의 `comment` / `_comment` 키는 편집기(layout-editor)와 개발자를 위한
* 설명 주석으로, 프론트엔드 런타임 렌더러(DynamicRenderer)는 이를 참조하지 않는다.
* 공개 서빙 응답에서만 제거하여 전송 크기를 줄이며, 편집 모드(withSourceMeta)에서는
* 호출하지 않아 보존한다. 배열/객체 노드를 재귀 순회하며 두 키만 unset 한다.
*
* @param array $node 정리 대상 레이아웃(또는 하위) 배열
* @return array comment 필드가 제거된 배열
*/
private function stripDeveloperComments(array $node): array
{
unset($node['comment'], $node['_comment']);
foreach ($node as $key => $value) {
if (is_array($value)) {
$node[$key] = $this->stripDeveloperComments($value);
}
}
return $node;
}
/**
* 컴포넌트의 props를 sanitize합니다.
*