bsSelector (GDG DevFest 2014)

75

description

bsSelector 발표자료 (GDG DevFest 2014)

Transcript of bsSelector (GDG DevFest 2014)

Page 1: bsSelector (GDG DevFest 2014)
Page 2: bsSelector (GDG DevFest 2014)

PAEK, Seung-Hyun

- ProjectBS 재배하는 농부 (committer)- SHOU Communications 근무-웹개발자 (JavaScript 사랑함 )

Page 3: bsSelector (GDG DevFest 2014)

projectBS

Page 4: bsSelector (GDG DevFest 2014)

projectBSbsJS??

Page 5: bsSelector (GDG DevFest 2014)

projectBSbsJS??

Page 6: bsSelector (GDG DevFest 2014)

#domID 요소의

1. 모서리를 둥글게2. 넓이를 지정3. 글자색을 지정4. Click event 설정5. 글자색 취득

Page 7: bsSelector (GDG DevFest 2014)

bsJS

var color = $('#domID').css( {

'borderRadius' : 5,‘color’ : ‘#fff’

} ).attr('width', 100).click(function(){alert(1)}).css('color');console.log(color) // "#fff"

Page 8: bsSelector (GDG DevFest 2014)

bsJS

var color = $('#domID').css( {

'borderRadius' : 5,‘color’ : ‘#fff’

} ).attr('width', 100).click(function(){alert(1)}).css('color');console.log(color) // "#fff"

var color = bs.Dom('#domID').S('border-radius', 5, '@width', 100, ‘click’, function(){alert(1)}, ’color', '#fff');

console.log(color) // "#fff"

Page 9: bsSelector (GDG DevFest 2014)

bsJS

var color = $('#domID').css( {

'borderRadius' : 5,‘color’ : ‘#fff’

} ).attr('width', 100).click(function(){alert(1)}).css('color');console.log(color) // "#fff"

var color = bs.Dom('#domID').S('border-radius', 5, '@width', 100, ‘click’, function(){alert(1)}, ’color', '#fff');

console.log(color) // "#fff"

호스트코드 : 110 byte

오브젝트 생성 : O함수호출 : 4 회

호스트코드 : 94 byte

오브젝트 생성 : X함수호출 : 1 회

Page 10: bsSelector (GDG DevFest 2014)

Selector engine왜 만들게되었나 ?

Page 11: bsSelector (GDG DevFest 2014)

bsJS 의Selector en-

gine

Page 12: bsSelector (GDG DevFest 2014)
Page 13: bsSelector (GDG DevFest 2014)

bsJS 에 독자적인 셀렉터를 갖고싶은데 ..

Page 14: bsSelector (GDG DevFest 2014)

bsJS 에 독자적인 셀렉터를 갖고싶은데 ..

ㅇㅇ ??

Page 15: bsSelector (GDG DevFest 2014)

승현이 니가 만들면 되겠네~!!

Page 16: bsSelector (GDG DevFest 2014)

승현이 니가 만들면 되겠네~!!

!!??(=_=);;;;

Page 17: bsSelector (GDG DevFest 2014)
Page 18: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 19: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 20: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 21: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 22: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 23: bsSelector (GDG DevFest 2014)

Selector processquery 의 tokenizer

요소 선택요소 순환요소 판정결과 반환

Page 24: bsSelector (GDG DevFest 2014)

query = 'ul.toc li.tocline2‘;tokens = ['ul', '.toc', ' ', 'li', ‘.tocline2‘];

if(tokens[i].charAt(0) == '#') document.getElementById(tokens[i].substr(1));else if(tokens[i].charAt(0) == '.') document.getElementByClassName(tokens[i].substr(1));else document.getElementsByTagName('*');

Page 25: bsSelector (GDG DevFest 2014)
Page 26: bsSelector (GDG DevFest 2014)

CSS2 spec 은 기본아냐 ?

Page 27: bsSelector (GDG DevFest 2014)

CSS2 spec 은 기본아냐 ?

ㅇㅇ ~

Page 28: bsSelector (GDG DevFest 2014)
Page 29: bsSelector (GDG DevFest 2014)

CSS3 spec 도하는김에 하지 ?

Page 30: bsSelector (GDG DevFest 2014)

CSS3 spec 도하는김에 하지 ?

으 .. 으응 ..;;;

Page 31: bsSelector (GDG DevFest 2014)
Page 32: bsSelector (GDG DevFest 2014)

CSS4 spec 이 새로 나왔던데 ?

Page 33: bsSelector (GDG DevFest 2014)

CSS4 spec 이 새로 나왔던데 ?

뭐 ?? ( 이 **야 )

Page 34: bsSelector (GDG DevFest 2014)

일단 완성성능이 궁금하다 !!

Page 35: bsSelector (GDG DevFest 2014)

일단 완성성능이 궁금하다 !!

Page 36: bsSelector (GDG DevFest 2014)

Sizzle speed

Page 37: bsSelector (GDG DevFest 2014)
Page 38: bsSelector (GDG DevFest 2014)

jsPerf.com

Page 39: bsSelector (GDG DevFest 2014)

getElementByIdgetElementsByTagName

getElementsByClass-Name

getElementsByNamequerySelectorAll

Page 40: bsSelector (GDG DevFest 2014)
Page 41: bsSelector (GDG DevFest 2014)
Page 42: bsSelector (GDG DevFest 2014)

ID TAG CLASS NAME

2,096,567 1,876,875 1,841,273 1,575,123

17,090,351 8,920,145 8,285,463 8,031,034

19,384,745 16,661,97317,559,67

819,073,48

5

Page 43: bsSelector (GDG DevFest 2014)
Page 44: bsSelector (GDG DevFest 2014)

ID TAG CLASS

124,963 126,480 106,504

1,091,549

222,199 210,918

2,020,367

321,119 339,747

Page 45: bsSelector (GDG DevFest 2014)

쿼리 패턴별로각 메서드 성능을

정리한 뒤효율이 좋은 부분에 반영

Page 46: bsSelector (GDG DevFest 2014)

jQuery

Sizzle

Mootools

bsSelector

0 500000 1000000 1500000 2000000 2500000

820424

1501379

1372821

2343437

Sizzle Benchmark

Page 47: bsSelector (GDG DevFest 2014)
Page 48: bsSelector (GDG DevFest 2014)

상황은 나아졌지만…

다음은 ???

Page 49: bsSelector (GDG DevFest 2014)

JavaScript 는인터프리터 언어

Page 50: bsSelector (GDG DevFest 2014)

인터프리터 ?

Page 51: bsSelector (GDG DevFest 2014)
Page 52: bsSelector (GDG DevFest 2014)

몇가지힌트를 통해 얻은

결론기계적인 접근

Page 53: bsSelector (GDG DevFest 2014)

몇가지힌트를 통해 얻은

결론기계적인 접근

Page 54: bsSelector (GDG DevFest 2014)

기계적인 접근 ??JavaScript 엔진이하는일을 줄이는것

Page 55: bsSelector (GDG DevFest 2014)

기계적인 접근 ??JavaScript 엔진이하는일을 줄이는것

Page 56: bsSelector (GDG DevFest 2014)

함수 호출을최소화

Page 57: bsSelector (GDG DevFest 2014)

함수 호출을 최소화 한다

Page 58: bsSelector (GDG DevFest 2014)

함수 호출을 최소화 한다

function Non function

16,830 54,080

49,063 49,436

51,524 52,066

Page 59: bsSelector (GDG DevFest 2014)

캐쉬 활용

Page 60: bsSelector (GDG DevFest 2014)

LinkedListgetElementsByTagName

getElementsByClassName

Page 61: bsSelector (GDG DevFest 2014)

var els = document.getElementsByTagName(‘div’);

Console.log(els.length); // 1

var newEl = document.createElement(‘div’);

document.body.appendChild(newEl);

console.log(els.length); // 2

Page 62: bsSelector (GDG DevFest 2014)

반복의 제거

Page 63: bsSelector (GDG DevFest 2014)

div

P[0] P[1] P[2]

‘p:last-child’

Page 64: bsSelector (GDG DevFest 2014)

새로운DOM 속성 활용

Page 65: bsSelector (GDG DevFest 2014)

element.childNodes;children.nodeType == 1;

VSelement.children

Page 66: bsSelector (GDG DevFest 2014)

이런 사실들을바탕으로 재작성

Page 67: bsSelector (GDG DevFest 2014)

이런 사실들을바탕으로 재작성

Page 68: bsSelector (GDG DevFest 2014)

Sizzle Mootools-slick

bsSelector

함수개수 140 93 13

라인수 1,214 2,037 305

용량 60,335 37,935 13,485

Page 69: bsSelector (GDG DevFest 2014)

그 결과

Page 70: bsSelector (GDG DevFest 2014)

Chrome

Page 71: bsSelector (GDG DevFest 2014)

IE10

Page 72: bsSelector (GDG DevFest 2014)

Sizzle

Mootools

bsSelector

0 2000000 4000000 6000000 8000000 10000000

3010190

2758557

9054979

1960305

1941198

7240460

with querySelectorAll

IE10 chrome

Page 73: bsSelector (GDG DevFest 2014)

Sizzle

Mootools

bsSelector

0 2000000 4000000 6000000 8000000 10000000

3155191

2662334

9036840

2408144

1749609

8094011

without querySelectorAll

IE10 chrome

Page 74: bsSelector (GDG DevFest 2014)

외제라고넘사벽은 아닙니다 .

국산도할 수 있어요 !!

Page 75: bsSelector (GDG DevFest 2014)

감사합니다 .ProjectBS group

https://www.facebook.com/groups/bs5js/github bsJS

http://ligo.kr/i7github bsSelectorhttp://ligo.kr/o8