Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Browser Computing Structure

Shogo Sensui
January 25, 2014

Browser Computing Structure

2014/1/25に開催されたFrontrend in FukuokaのBrowser Computing Structureのセッションの資料です。

Shogo Sensui

January 25, 2014
Tweet

More Decks by Shogo Sensui

Other Decks in Programming

Transcript

  1. Keep 60FPS • FPS = Frames Per Second • ϒϥ΢β͸1ඵؒʹ60ճϦϑϨογϡ͢Δ

    • 60FPSΛҡ࣋͢Δʹ͸1ϑϨʔϜͷॲཧΛ16.67ms ʹऩΊΔ (16.67ms=1000ms / 60FPs) • Ұൠతʹ30FPSग़͍ͯΕ͹׈Β͔Ͱ͋Δ
  2. function Timer() { this.timerId = setInterval(function() { console.log('This is timer

    log.'); }, 1000); } ! ! ! var timer = new Timer(); timer = null;
  3. function Timer() { this.timerId = setInterval(function() { console.log('This is timer

    log.'); }, 1000); } ! ! ! var timer = new Timer(); timer = null; ݺͼग़͠ݩΛഁغͯ͠΋ λΠϚʔ͕࣮ߦ͞Εଓ͚Δ
  4. function Timer() { this.timerId = setInterval(function() { console.log('This is timer

    log.'); }, 1000); this.stop = function() { clearInterval(this.timerId); }; } ! ! ! var timer = new Timer(); timer.stop(); timer = null;
  5. function Timer() { this.timerId = setInterval(function() { console.log('This is timer

    log.'); }, 1000); this.stop = function() { clearInterval(this.timerId); }; } ! ! ! var timer = new Timer(); timer.stop(); timer = null; λΠϚʔ͸
 ͪΌΜͱࢭΊΔ͜ͱʂ
  6. function Closure() { var value = 1000; return function() {

    return value; }; } value͸ؔ਺͔Β ࢀর͞Εଓ͚ͯ͠·͏
  7. function Closure() { var value = 1000; return function() {

    var another = 2000; return another; }; }
  8. function Closure() { var value = 1000; return function() {

    var another = 2000; return another; }; } value͸ࢀর͞Εͳ͘ͳΔ ͷͰGCʹճऩ͞ΕΔ
  9. var family = []; ! var child = { age:

    10 container: family }; ! var parent = { child: child, container: family }; ! family.push(child); family.push(parent);
  10. var grandparent = { child: parent, container: family }; !

    family.push(parent); ઇͩΔ·ࣜʹ૿͑ΔϝϞϦ
  11. A C

  12. A C

  13. A C

  14. var object = { foo: 1, bar: 2 }; console.log(object);

    object = null; ίϯιʔϧ͔Βࢀর͞Ε GC͔Βճऩ͞Εͳ͍
  15. ArrayͷforEach()ΑΓforͰϧʔϓɹΞχϝʔγϣϯʹ͸ requestAnimationFrame()ɹ“use strict”;Λ࢖͏ɹ try/catchʢྫ֎ͷัଊʣ͸ॏ͍ɹparseInt()ΑΓՃݮԋ ࢉͰΩϟετ͢ΔɹDOMͷ୳ࡧ΍ૢ࡞͸࠷খݶʹɹ୹͍ؔ਺ͷ ΠϯϥΠϯԽɹeval()΍with()Λ࢖Θͳ͍ɹnew Date()Α Γdate.now()ɹධՁॱͷ޻෉ɹਖ਼نදݱͷΩϟογϡɹॏ͍ ॲཧͷඇಉظԽ(WebWorker)ɹArrayͷforEach()ΑΓfor Ͱϧʔϓɹ

    Ξχϝʔγϣϯʹ͸requestAnimationFrame()ɹ “use strict”;Λ࢖͏ɹtry/catchʢྫ֎ͷัଊʣ͸ॏ͍ɹ parseInt()ΑΓՃݮԋࢉͰΩϟετ͢ΔɹDOMͷ୳ࡧ΍ૢ࡞ ͸࠷খݶʹɹ୹͍ؔ਺ͷΠϯϥΠϯԽɹeval()΍with()Λ࢖ Θͳ͍ɹnew Date()ΑΓdate.now()ɹධՁॱͷ޻෉ɹਖ਼ن දݱͷΩϟογϡɹॏ͍ॲཧͷඇಉظԽ(WebWorker)ɹetc…
  16. Ϋϥεͷఆ͕ٛ͋ͬͨΒ… function Point(x, y) { this.x = x; this.y =

    y; } JITίϯύΠϧ࣌ʹΫϥε ͷ੩తͳ࣮ଶΛੜ੒͢Δ function Point(x, y) { this.x = x; this.y = y; } Hidden Class
  17. Ϋϥεͷఆ͕ٛ͋ͬͨΒ… function Point(x, y) { this.x = x; this.y =

    y; } JITίϯύΠϧ࣌ʹΫϥε ͷ੩తͳ࣮ଶΛੜ੒͢Δ function Point(x, y) { this.x = x; this.y = y; } Hidden Class var point = new Point(); ͔࣍ΒίϯύΠϧࡁͷ ΫϥεΛࢀর͢ΔͷͰߴ଎
  18. Ϋϥεͷఆ͕ٛ͋ͬͨΒ… function Point(x, y) { this.x = x; this.y =

    y; } JITίϯύΠϧ࣌ʹΫϥε ͷ੩తͳ࣮ଶΛੜ੒͢Δ function Point(x, y) { this.x = x; this.y = y; } Hidden Class var point = new Point(); ͔࣍ΒίϯύΠϧࡁͷ ΫϥεΛࢀর͢ΔͷͰߴ଎
  19. function Point(x, y) { this.x = x; this.y = y;

    } Point.name = 'Name'; Hidden ClassΛ ࠶౓ੜ੒ͯ͠͠·͏ Hidden Class ఆٛΛ్தͰมߋ͢Δͱ… Point.name = 'Name';
  20. function Point(x, y) { this.x = x; this.y = y;

    } Point.name = 'Name'; Hidden ClassΛ ࠶౓ੜ੒ͯ͠͠·͏ Hidden Class ఆٛΛ్தͰมߋ͢Δͱ… Point.name = 'Name'; ϒϥ΢β͕࣮ߦ࣌ʹ࠷దԽͨ͠ίʔυΛ ͳΔ΂͘มߋ͠ͳ͍Α͏ʹ͢Δʂ
  21. Photo Credits • http://www.flickr.com/photos/66331098@N03/6041212579 • http://www.flickr.com/photos/danichro/7284517300 • http://www.flickr.com/photos/articnomad/16153058/ • http://www.flickr.com/photos/sfgirlbybay/2739327181/

    • http://www.flickr.com/photos/30859306@N00/3331140550 • http://www.flickr.com/photos/45540741@N06/7365063522/ • http://www.flickr.com/photos/chrissinjo/5368405044 • http://www.flickr.com/photos/cloudy-day/5319042359 • http://www.flickr.com/photos/57490760@N04/7218896186