awesome-interview/assets/js/b728f6fe.9790f343.js

1 line
13 KiB
JavaScript

"use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[5211],{3905:function(e,t,r){r.d(t,{Zo:function(){return u},kt:function(){return k}});var n=r(7294);function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var p=n.createContext({}),c=function(e){var t=n.useContext(p),r=t;return e&&(r="function"==typeof e?e(t):i(i({},t),e)),r},u=function(e){var t=c(e.components);return n.createElement(p.Provider,{value:t},e.children)},m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},s=n.forwardRef((function(e,t){var r=e.components,a=e.mdxType,o=e.originalType,p=e.parentName,u=l(e,["components","mdxType","originalType","parentName"]),s=c(r),k=a,d=s["".concat(p,".").concat(k)]||s[k]||m[k]||o;return r?n.createElement(d,i(i({ref:t},u),{},{components:r})):n.createElement(d,i({ref:t},u))}));function k(e,t){var r=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var o=r.length,i=new Array(o);i[0]=s;var l={};for(var p in t)hasOwnProperty.call(t,p)&&(l[p]=t[p]);l.originalType=e,l.mdxType="string"==typeof e?e:a,i[1]=l;for(var c=2;c<o;c++)i[c]=r[c];return n.createElement.apply(null,i)}return n.createElement.apply(null,r)}s.displayName="MDXCreateElement"},2983:function(e,t,r){r.r(t),r.d(t,{frontMatter:function(){return l},contentTitle:function(){return p},metadata:function(){return c},toc:function(){return u},default:function(){return s}});var n=r(7462),a=r(3366),o=(r(7294),r(3905)),i=["components"],l={sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",sidebar_position:2},p="\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",c={unversionedId:"book1/browser-repain-reflow",id:"book1/browser-repain-reflow",isDocsHomePage:!1,title:"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book1/browser-repain-reflow.md",sourceDirName:"book1",slug:"/book1/browser-repain-reflow",permalink:"/awesome-interview/book1/browser-repain-reflow",tags:[],version:"current",sidebarPosition:2,frontMatter:{sidebar_label:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8",sidebar_position:2},sidebar:"tutorialSidebar",previous:{title:"\u6d4f\u89c8\u5668\uff1a\u6d4f\u89c8\u5668\u8de8\u57df",permalink:"/awesome-interview/book1/browser-cross-origin"},next:{title:"\u5de5\u7a0b\u5316\uff1aWebpack \u5de5\u4f5c\u6d41\u7a0b",permalink:"/awesome-interview/book1/engineer-webpack-workflow"}},u=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",children:[]},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",children:[]},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",children:[{value:"1. \u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8",id:"1-\u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8",children:[]},{value:"2. \u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8",id:"2-\u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8",children:[]}]},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",children:[]}],m={toc:u};function s(e){var t=e.components,r=(0,a.Z)(e,i);return(0,o.kt)("wrapper",(0,n.Z)({},m,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8"},"\u6d4f\u89c8\u5668\u7684\u91cd\u6392\u91cd\u7ed8"),(0,o.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"\u5982\u4f55\u63d0\u5347\u9875\u9762\u6e32\u67d3\u6027\u80fd"),(0,o.kt)("li",{parentName:"ul"},"\u5982\u4f55\u51cf\u5c11\u9875\u9762\u91cd\u6392\u91cd\u7ed8"),(0,o.kt)("li",{parentName:"ul"},"\u54ea\u4e9b\u884c\u4e3a\u4f1a\u5f15\u8d77\u91cd\u6392/\u91cd\u7ed8")),(0,o.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,o.kt)("p",null,(0,o.kt)("inlineCode",{parentName:"p"},"\u6e32\u67d3\u6027\u80fd")," ",(0,o.kt)("inlineCode",{parentName:"p"},"Layout")," ",(0,o.kt)("inlineCode",{parentName:"p"},"Paint")),(0,o.kt)("p",null,"\u6d4f\u89c8\u5668\u6e32\u67d3\u5927\u81f4\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff0c\u5176\u4e2d\u5728\u89e3\u6790 HTML \u540e\uff0c\u4f1a\u4f9d\u6b21\u8fdb\u5165 Layout \u548c Paint \u9636\u6bb5\u3002",(0,o.kt)("strong",{parentName:"p"},"\u6837\u5f0f\u6216\u8282\u70b9\u7684\u66f4\u6539\uff0c\u4ee5\u53ca\u5bf9\u5e03\u5c40\u4fe1\u606f\u7684\u8bbf\u95ee\u7b49"),"\uff0c\u90fd\u6709\u53ef\u80fd\u5bfc\u81f4\u91cd\u6392\u548c\u91cd\u7ed8\u3002\u800c\u91cd\u6392\u548c\u91cd\u7ed8\u7684\u8fc7\u7a0b\u5728",(0,o.kt)("strong",{parentName:"p"},"\u4e3b\u7ebf\u7a0b"),"\u4e2d\u8fdb\u884c\uff0c\u8fd9\u610f\u5473\u7740\u4e0d\u5408\u7406\u7684\u91cd\u6392\u91cd\u7ed8\u4f1a\u5bfc\u81f4",(0,o.kt)("strong",{parentName:"p"},"\u6e32\u67d3\u5361\u987f\uff0c\u7528\u6237\u4ea4\u4e92\u6ede\u540e"),"\u7b49\u6027\u80fd\u95ee\u9898\u3002"),(0,o.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,o.kt)("h3",{id:"1-\u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8"},"1. \u4ec0\u4e48\u662f\u91cd\u6392\u91cd\u7ed8"),(0,o.kt)("p",null,(0,o.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/126033732-d5002255-1c88-4dee-9371-da166aacdca9.png",alt:"image"})),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Layout\uff08\u5e03\u5c40\uff09")),(0,o.kt)("blockquote",null,(0,o.kt)("p",{parentName:"blockquote"},"\u6307\u6d4f\u89c8\u5668\u8ba1\u7b97\u5404\u5143\u7d20\u7684\u51e0\u4f55\u4fe1\u606f\uff0c\u786e\u5b9a\u5143\u7d20\u7684\u5927\u5c0f\u4ee5\u53ca\u5728\u9875\u9762\u4e2d\u7684\u4f4d\u7f6e\u7b49\u4fe1\u606f\u7684\u8fc7\u7a0b\u3002")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Paint\uff08\u7ed8\u5236/\u6805\u683c\u5316\uff09")),(0,o.kt)("blockquote",null,(0,o.kt)("p",{parentName:"blockquote"},"\u6307\u5c06\u6e32\u67d3\u6811\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\u8f6c\u6362\u6210\u5c4f\u5e55\u4e0a\u7684\u5b9e\u9645\u50cf\u7d20\u7684\u8fc7\u7a0b\u3002")),(0,o.kt)("p",null,"\u6d4f\u89c8\u5668\u4ece\u83b7\u53d6\u6587\u6863\u3001\u6837\u5f0f\u3001\u811a\u672c\u7b49\u5185\u5bb9\uff0c\u5230\u6700\u7ec8\u6e32\u67d3\u7ed3\u679c\u5230\u5c4f\u5e55\u4e0a\uff0c\u9700\u8981\u7ecf\u8fc7\u5982\u56fe\u6240\u793a\u7684\u6b65\u9aa4\u3002\u800c DOM \u6216 CSSOM \u88ab\u4fee\u6539\uff0c\u4f1a\u5bfc\u81f4\u6d4f\u89c8\u5668\u91cd\u590d\u6267\u884c\u56fe\u4e2d\u7684\u6b65\u9aa4\u3002\u91cd\u6392\u548c\u91cd\u7ed8\uff0c\u672c\u8d28\u4e0a\u6307\u7684\u5c31\u662f\u5206\u522b\u91cd\u65b0\u89e6\u53d1 Layout \u548c Paint \u7684\u8fc7\u7a0b\uff0c\u4e14\u91cd\u6392\u5fc5\u5b9a\u5bfc\u81f4\u91cd\u7ed8\u3002"),(0,o.kt)("h4",{id:"\u5f15\u8d77\u91cd\u6392\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c"},"\u5f15\u8d77\u91cd\u6392/\u91cd\u7ed8\u7684\u5e38\u89c1\u64cd\u4f5c"),(0,o.kt)("ol",null,(0,o.kt)("li",{parentName:"ol"},"\u5916\u89c2\u6709\u53d8\u5316\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,o.kt)("strong",{parentName:"li"},"\u91cd\u7ed8"),"\u3002\u76f8\u5173\u7684\u6837\u5f0f\u5c5e\u6027\u5982 ",(0,o.kt)("inlineCode",{parentName:"li"},"color")," ",(0,o.kt)("inlineCode",{parentName:"li"},"opacity")," \u7b49\u3002"),(0,o.kt)("li",{parentName:"ol"},"\u5e03\u5c40\u7ed3\u6784\u6216\u8282\u70b9\u5185\u5bb9\u53d8\u5316\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,o.kt)("strong",{parentName:"li"},"\u91cd\u6392"),"\u3002\u76f8\u5173\u7684\u6837\u5f0f\u5c5e\u6027\u5982 ",(0,o.kt)("inlineCode",{parentName:"li"},"height")," ",(0,o.kt)("inlineCode",{parentName:"li"},"float")," ",(0,o.kt)("inlineCode",{parentName:"li"},"position")," \u7b49\u3002",(0,o.kt)("ul",{parentName:"li"},(0,o.kt)("li",{parentName:"ul"},"\u76d2\u5b50\u5c3a\u5bf8\u548c\u7c7b\u578b\u3002"),(0,o.kt)("li",{parentName:"ul"},"\u5b9a\u4f4d\u65b9\u6848\uff08\u6b63\u5e38\u6d41\u3001\u6d6e\u52a8\u548c\u7edd\u5bf9\u5b9a\u4f4d\uff09\u3002"),(0,o.kt)("li",{parentName:"ul"},"\u6587\u6863\u6811\u4e2d\u5143\u7d20\u4e4b\u95f4\u7684\u5173\u7cfb\u3002"),(0,o.kt)("li",{parentName:"ul"},"\u5916\u90e8\u4fe1\u606f\uff08\u5982\u89c6\u53e3\u5927\u5c0f\u7b49\uff09\u3002"))),(0,o.kt)("li",{parentName:"ol"},"\u83b7\u53d6\u5e03\u5c40\u4fe1\u606f\u65f6\uff0c\u4f1a\u5bfc\u81f4",(0,o.kt)("strong",{parentName:"li"},"\u91cd\u6392"),"\u3002\u76f8\u5173\u7684\u65b9\u6cd5\u5c5e\u6027\u5982 ",(0,o.kt)("inlineCode",{parentName:"li"},"offsetTop")," ",(0,o.kt)("inlineCode",{parentName:"li"},"getComputedStyle")," \u7b49\u3002")),(0,o.kt)("h3",{id:"2-\u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8"},"2. \u5982\u4f55\u51cf\u5c11\u91cd\u6392\u91cd\u7ed8"),(0,o.kt)("p",null,(0,o.kt)("img",{parentName:"p",src:"https://user-images.githubusercontent.com/17002181/126033739-3e689aab-fcd8-4928-9e6d-6a047ab2a8c9.png",alt:"image"})),(0,o.kt)("h4",{id:"\u610f\u4e49"},"\u610f\u4e49"),(0,o.kt)("p",null,"\u5927\u591a\u6570\u663e\u793a\u5668\u7684\u5237\u65b0\u7387\u662f 60FPS\uff08frames per second\uff09\u3002\u7406\u60f3\u60c5\u51b5\u4e0b\uff0c\u6d4f\u89c8\u5668\u9700\u8981\u5728 1/60 \u79d2\u5185\u5b8c\u6210\u6e32\u67d3\u9636\u6bb5\u5e76\u4ea4\u4ed8\u4e00\u5e27\u3002\u8fd9\u6837\u7528\u6237\u5c31\u4f1a\u770b\u5230\u4e00\u4e2a\u4ea4\u4e92\u6d41\u7545\u7684\u9875\u9762\u3002"),(0,o.kt)("p",null,"\u5728\u4ea4\u4e92\u9636\u6bb5\uff0c\u9875\u9762\u66f4\u65b0\uff08\u4e00\u822c\u662f\u901a\u8fc7\u6267\u884c JavaScript \u6765\u89e6\u53d1\uff09\u901a\u5e38\u4f1a\u89e6\u53d1\u91cd\u6392\u548c\u91cd\u7ed8\u3002\u4e3a\u4e86\u63d0\u5347\u6d4f\u89c8\u5668\u6e32\u67d3\u6548\u7387\uff0c\u5e94\u5f53\u5c3d\u53ef\u80fd\u51cf\u5c11\u91cd\u7ed8\u91cd\u6392\uff0c\u964d\u4f4e\u6d4f\u89c8\u5668\u6e32\u67d3\u8017\u8d39\u7684\u65f6\u95f4\uff0c\u5c3d\u5feb\u5c06\u5185\u5bb9\u6e32\u67d3\u5230\u5c4f\u5e55\u4e0a\u3002"),(0,o.kt)("h4",{id:"\u89e3\u51b3\u65b9\u6848"},"\u89e3\u51b3\u65b9\u6848"),(0,o.kt)("ol",null,(0,o.kt)("li",{parentName:"ol"},"\u5bf9 DOM \u8fdb\u884c\u6279\u91cf\u5199\u5165\u548c\u8bfb\u53d6\uff08\u901a\u8fc7\u865a\u62df DOM \u6216\u8005 DocumentFragment \u5b9e\u73b0\uff09\u3002"),(0,o.kt)("li",{parentName:"ol"},"\u907f\u514d\u5bf9\u6837\u5f0f\u9891\u7e41\u64cd\u4f5c\uff0c\u4e86\u89e3\u5e38\u7528\u6837\u5f0f\u5c5e\u6027\u89e6\u53d1 Layout / Paint / Composite \u7684",(0,o.kt)("a",{parentName:"li",href:"https://csstriggers.com/"},"\u673a\u5236"),"\uff0c\u5408\u7406\u4f7f\u7528\u6837\u5f0f\u3002"),(0,o.kt)("li",{parentName:"ol"},"\u5408\u7406\u5229\u7528\u7279\u6b8a\u6837\u5f0f\u5c5e\u6027\uff08\u5982 transform: translateZ(0) \u6216\u8005 will-change\uff09\uff0c\u5c06\u6e32\u67d3\u5c42\u63d0\u5347\u4e3a\u5408\u6210\u5c42\uff0c\u5f00\u542f GPU \u52a0\u901f\uff0c\u63d0\u9ad8\u9875\u9762\u6027\u80fd\u3002"),(0,o.kt)("li",{parentName:"ol"},"\u6309\u9700\u7f13\u5b58\u5e03\u5c40\u4fe1\u606f\uff0c\u907f\u514d\u9891\u7e41\u8bfb\u53d6\u3002")),(0,o.kt)("p",null,"\u53e6\u5916\uff0c\u53ef\u4ee5\u501f\u52a9 DevTools Performance \u9762\u677f\u6765\u67e5\u770b\u4ea7\u751f\u91cd\u6392\u91cd\u7ed8\u4efb\u52a1\u5360\u7528\u4e3b\u7ebf\u7a0b\u7684\u60c5\u51b5\u548c\u8c03\u7528\u4ee3\u7801\u3002"),(0,o.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,o.kt)("ol",null,(0,o.kt)("li",{parentName:"ol"},(0,o.kt)("a",{parentName:"li",href:"https://developers.google.com/web/fundamentals/performance/critical-rendering-path/render-tree-construction?hl=zh-cn"},"\u6e32\u67d3\u6811\u6784\u5efa\u3001\u5e03\u5c40\u53ca\u7ed8\u5236")),(0,o.kt)("li",{parentName:"ol"},(0,o.kt)("a",{parentName:"li",href:"https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing"},"\u907f\u514d\u5927\u578b\u3001\u590d\u6742\u7684\u5e03\u5c40\u548c\u5e03\u5c40\u6296\u52a8")),(0,o.kt)("li",{parentName:"ol"},(0,o.kt)("a",{parentName:"li",href:"https://csstriggers.com/"},"CSS \u5c5e\u6027\u89e6\u53d1\u5e03\u5c40\u3001\u7ed8\u5236\u53ca\u5408\u6210\u7684\u6570\u636e")),(0,o.kt)("li",{parentName:"ol"},(0,o.kt)("a",{parentName:"li",href:"https://gist.github.com/paulirish/5d52fb081b3570c81e3a"},"What forces layout / reflow"))))}s.isMDXComponent=!0}}]);