perf(core): 서빙 API 부팅 비용 최적화 (information_schema 가드 + 훅/오토로드/config 캐시)
매 요청 균일하게 발생하던 부팅 오버헤드를 4개 축에서 제거한다. - 설치 완료 상태에서 매 요청 반복되던 information_schema 조회(알림·본인인증 테이블 hasTable)를 installer_completed 가드로 스킵. 미설치 환경은 기존 hasTable 폴백 유지. - 코어+모듈+플러그인 정적 훅 매핑을 bootstrap/cache/hooks.php 에 사전 계산해 매 요청 디렉토리 스캔·리플렉션·클래스 로딩을 제거(route:cache 동형). 등록↔발화 계약·매핑 바이트 동일. 확장/코어 변경 시 자동 재생성, 캐시 부재·손상은 스캔 폴백. - 확장 소스(Modules\*/Plugins\*)를 autoload-extensions.php 의 classmap 에 편입해 findFile 파일시스템 스캔을 제거(느린 FS·cold OPcache 환경 직격). 클래스 로딩은 여전히 lazy, PSR-4 폴백 유지. - config 캐시를 변경 지점(설정 저장/코어·확장 업데이트/APP_KEY 재생성/설치 완료)에서 clear 후 즉시 재생성하도록 ConfigCacheHelper 로 일원화. clear 만 하고 방치돼 캐시가 영구 비활성으로 남던 성능 손실 제거. HookCacheManager::read 요청당 1회 로드(memo)로 중복 파싱 제거. 부팅 매핑 fingerprint 스캔↔캐시 완전 동일(229 action + 35 filter). 신규/수정 8개 스위트 54 pass. 순수 내부 부팅 인프라 — 확장 공개 표면·훅 계약 불변.
This commit is contained in:
1 parent
deacbc7b66
commit
c08dae7cb0
41 files changed
+2590
-131
No files matched your search
@@ -0,0 +1,61 @@
|
||||
# audit:allow test-scenario-coverage reason: lifecycle_event 축(install/update/uninstall/core_update/activate)은 FQCN 추출·classmap 상태 축과 직교하는 재생성 관심사라 cross product 가 인위적. 재생성 효과는 test_files 의 HooksCacheCommandTest(extension:update-autoload 재생성) + ExtensionManagerComposerTest 가 커버하고, FQCN/classmap/vendor격리는 ExtensionSourceClassmapTest 가 per-case 커버. effects 전량은 아래 @effects 마킹으로 검증.
|
||||
coverage_strategy: pairwise
|
||||
|
||||
feature: 확장 소스 classmap (Extension Source Classmap / B2)
|
||||
|
||||
description: |
|
||||
서빙 API 부팅 비용 최적화. 확장 소스 클래스(Modules\*, Plugins\*)를 autoload-extensions.php 의
|
||||
src_classmap 에 사전 계산(FQCN → 경로)하여 진입점에서 ClassLoader::addClassMap() 으로 등록한다.
|
||||
findFile 이 파일시스템 스캔(is_dir/file_exists stat) 없이 in-memory 맵에서 즉시 경로를 반환
|
||||
→ cold OPcache / 느린 파일시스템 환경의 findFile 비용 제거.
|
||||
|
||||
핵심 동작:
|
||||
- buildSourceClassmap: PSR-4 디렉토리 재귀 스캔 + 토큰 기반 FQCN 추출(class/interface/trait/enum)
|
||||
- 소스 클래스만 대상 — 서드파티 vendor 는 각 확장 vendor/autoload.php(별도 ClassLoader) 격리 유지
|
||||
- 지연 로드: classmap 은 경로만 제공, include 는 실제 사용 시점 (매 요청 전량 로드 아님)
|
||||
- PSR-4 폴백 보존: classmap 미포함 클래스는 기존 PSR-4 경로로 폴백 (안전망)
|
||||
- 재생성: psr4 와 동일 생명주기 — install/update/uninstall → updateComposerAutoload,
|
||||
코어 업데이트 → extension:update-autoload. activate/deactivate 는 autoload 미수정
|
||||
(collectAutoloads 가 설치된 전체 포함 → 비활성도 이미 맵에 존재)
|
||||
|
||||
axes:
|
||||
declaration_kind: [class, interface, trait, enum]
|
||||
extension_type: [module, plugin]
|
||||
classmap_state: [present_hit, absent_psr4_fallback, path_outside_namespace]
|
||||
lifecycle_event: [install, update, uninstall, activate_no_regen, core_update]
|
||||
|
||||
exclusions:
|
||||
- { classmap_state: path_outside_namespace, declaration_kind: interface, reason: "네임스페이스 불일치 제외는 선언 종류 무관 — class 케이스로 대표" }
|
||||
- { classmap_state: path_outside_namespace, declaration_kind: trait, reason: "동일" }
|
||||
- { classmap_state: path_outside_namespace, declaration_kind: enum, reason: "동일" }
|
||||
- { lifecycle_event: activate_no_regen, classmap_state: absent_psr4_fallback, reason: "활성화는 autoload 미수정 — classmap 상태 무관(이미 설치 시 생성됨)" }
|
||||
|
||||
effects:
|
||||
# FQCN 추출 정확성
|
||||
- extracts_fqcn_for_class_declaration
|
||||
- extracts_fqcn_for_interface_declaration
|
||||
- extracts_fqcn_for_trait_declaration
|
||||
- extracts_fqcn_for_enum_declaration
|
||||
- maps_fqcn_to_correct_relative_path
|
||||
# 포함/제외 범위
|
||||
- ignores_files_outside_declared_namespace
|
||||
- skips_files_without_top_level_declaration
|
||||
- missing_directory_returns_empty
|
||||
# vendor 격리 (설계 불변조건)
|
||||
- generated_src_classmap_excludes_vendor_paths
|
||||
- generated_src_classmap_only_extension_namespaces
|
||||
# 런타임 등록 + 폴백
|
||||
- classmap_present_findFile_hits_without_filesystem_stat
|
||||
- classmap_absent_findFile_falls_back_to_psr4
|
||||
- class_loading_remains_lazy_include_on_use
|
||||
# 재생성 생명주기
|
||||
- install_regenerates_src_classmap_via_updateComposerAutoload
|
||||
- update_regenerates_src_classmap
|
||||
- uninstall_regenerates_src_classmap
|
||||
- core_update_regenerates_src_classmap_via_extension_update_autoload
|
||||
- activate_does_not_regenerate_but_installed_classes_already_mapped
|
||||
|
||||
test_files:
|
||||
- tests/Unit/Extension/ExtensionSourceClassmapTest.php
|
||||
- tests/Unit/Extension/ExtensionManagerComposerTest.php
|
||||
- tests/Feature/Console/HooksCacheCommandTest.php
|
||||
@@ -0,0 +1,67 @@
|
||||
feature: 정적 훅 매핑 캐시 (Static Hook Cache)
|
||||
|
||||
description: |
|
||||
서빙 API 부팅 비용 최적화. 매 요청 코어(app/Listeners 재귀 스캔) + 모듈/플러그인
|
||||
(getHookListeners) 정적 훅 리스너의 발견·리플렉션·getSubscribedHooks() 클래스 로딩을
|
||||
bootstrap/cache/hooks.php 캐시로 제거한다.
|
||||
|
||||
핵심 동작:
|
||||
- 캐시 우선 등록: registerCoreHookListenersFromCache / registerExtensionHookListenersFromCache
|
||||
가 존재하면 스캔·리플렉션 없이 사전 계산 매핑으로 등록
|
||||
- 바이트 동일 게이트: HookListenerRegistrar::registerFromCache 가 register 와 동일한
|
||||
applySubscribedHooks 에 위임 → 훅 매핑(이름·우선순위·콜백 수) 완전 일치, 발화 누락 0
|
||||
- 안전 폴백: 캐시 부재/손상/구조 불일치/테스트 환경에서 기존 스캔 경로로 폴백
|
||||
- 동적 훅(알림)은 캐시 대상 아님 — dynamic 플래그만 저장하여 boot 후반부 지연 실행 순서 유지.
|
||||
getAllActive() 는 이미 ['notification'] 태그 캐시라 캐시 히트 시 DB 조회 0
|
||||
- 재생성(무효화=재생성): 확장 install/update → updateComposerAutoload,
|
||||
코어 업데이트 → clearAllCaches → extension:update-autoload, 코어 리스너 배포 → hooks:cache
|
||||
|
||||
# registration 축(cache_state·registration_source·listener_type)과 regeneration_trigger 는
|
||||
# 상호 직교 관심사(등록 시점 vs 재생성 시점)라 full cross product 는 인위적 조합을 만든다.
|
||||
# pairwise 로 모든 축 값 쌍을 커버하되 케이스 수를 실측 검증 가능한 범위로 유지한다.
|
||||
coverage_strategy: pairwise
|
||||
|
||||
axes:
|
||||
cache_state: [absent, present_valid, corrupted_broken_structure, present_but_testing_env]
|
||||
registration_source: [core, module, plugin]
|
||||
listener_type: [action_queued, action_sync, filter, dynamic]
|
||||
regeneration_trigger: [extension_update, core_update, hooks_cache_command, hooks_clear_command]
|
||||
|
||||
exclusions:
|
||||
- { cache_state: present_but_testing_env, registration_source: core, reason: "테스트 환경은 항상 스캔 폴백 — 캐시 경로 미진입 (registration_source 무관)" }
|
||||
- { listener_type: dynamic, registration_source: module, reason: "동적 훅(registerDynamicHooks)은 코어 NotificationHookListener 전용 — 모듈/플러그인 매니저는 동적 훅 미처리" }
|
||||
- { listener_type: dynamic, registration_source: plugin, reason: "동일 — 동적 훅은 코어 boot 후반부 전용" }
|
||||
- { regeneration_trigger: hooks_clear_command, cache_state: absent, reason: "이미 부재 상태 clear 는 무동작 성공 (route:clear 동형)" }
|
||||
|
||||
effects:
|
||||
# 바이트 동일 게이트 (발화 누락 0)
|
||||
- cache_path_registration_byte_identical_to_scan_path
|
||||
- cache_registered_action_dispatches_queue_job
|
||||
- cache_registered_sync_action_executes_immediately
|
||||
- cache_registered_filter_executes_synchronously_and_returns_value
|
||||
# 안전 폴백
|
||||
- absent_cache_falls_back_to_scan_registration
|
||||
- corrupted_cache_returns_null_and_falls_back_to_scan
|
||||
- testing_env_always_scans_ignoring_cache_file
|
||||
# 동적 훅
|
||||
- dynamic_listener_flagged_in_core_cache
|
||||
- dynamic_flagged_listener_deferred_to_boot_tail_like_scan_path
|
||||
- notification_getAllActive_cache_hit_issues_zero_db_query
|
||||
# 캐시 생성 구조
|
||||
- generate_produces_three_bucket_cache_core_modules_plugins
|
||||
- each_cache_entry_has_listener_hooks_and_dynamic_keys
|
||||
- listener_class_not_autoloaded_at_boot_when_registered_from_cache
|
||||
# 재생성 (무효화=재생성)
|
||||
- extension_update_regenerates_hook_cache_via_updateComposerAutoload
|
||||
- core_update_regenerates_hook_cache_via_clearAllCaches_extension_update_autoload
|
||||
- hooks_cache_command_generates_cache_file
|
||||
- hooks_clear_command_removes_cache_file
|
||||
- hooks_clear_is_safe_when_cache_absent
|
||||
- removed_core_listener_dropped_from_cache_after_regeneration
|
||||
|
||||
test_files:
|
||||
- tests/Unit/Extension/HookCacheManagerTest.php
|
||||
- tests/Unit/Extension/HookListenerRegistrarTest.php
|
||||
- tests/Feature/Console/HooksCacheCommandTest.php
|
||||
- tests/Unit/Services/NotificationDefinitionServiceTest.php
|
||||
- tests/Unit/Extension/InstallerCompletedGuardTest.php
|
||||
Reference in new issue
Block a user