🖊️
Javascript-Advanced
  • Javascript 고급
  • 1) Closure
    • Closure
    • Memory Leak
  • 2) Arrow Function
    • Class To Function ( babel )
    • Normal function vs Arrow Function
    • Class에서 사용하지마!!!
    • 그 외
  • 3) Hidden Class
    • Prototype Chainning
    • Hidden Class
    • Inline Cache
  • 4) setTimeout
    • setTimeout
  • 5) Nodejs
    • Execution-context
    • 내부 동작 원리
    • Crypto
  • 6) Thinking
    • 요청이 무한대로 들어오면 어떻게 될까?
Powered by GitBook
On this page
  1. 3) Hidden Class

Inline Cache

PreviousHidden ClassNextsetTimeout

Last updated 4 years ago

Was this helpful?

CtrlK

Was this helpful?

function test(){
	const a = { name: 'a' }
	const b = { name: 'b' }
	const c = { name: 'c' }
	const d = { name: 'd' }
	const e = { name: 'e' }
  const arr = [a,b,c,d,e]
  const getName = (obj) => obj.name;
  for (var i = 0; i < 1000; i++) {
      getName(arr[i & arr.length-1]);
  }
}
test()
function test(){
	const a = { name: 'a', address: 'a' }
	const b = { name: 'b', go: 'b' }
	const c = { name: 'c', apple: 'pie' }
	const d = { name: 'd', phone: 'number' }
	const e = { name: 'e' }
  const arr = [a,b,c,d,e]
  const getName = (obj) => obj.name;
  for (var i = 0; i < 1000; i++) {
      getName(arr[i & arr.length-1]);
  }
}
test()

그림에서 보는 거와 같이 23퍼나 느리다

---

인라인 캐싱의 상태

  • UNINITIALIZED(0)

  • PREMONOMORPHIC(1) - 1번째 접근

  • MONOMORPHIC(1) - 2번째 접근

  • 3번째 접근 (cache hit)

  • POLYMORPHIC(P) - 다른 Shape(Hidden Class)가 접근할 경우. 4개까지 가능.

  • MEGAMORPHIC(N) - 최대 4개 캐시 가능.

http://www.egocube.pe.kr/lecture/content/html-javascript/202003240001