gpt4 book ai didi

angular - 为什么 Angular 7 框架在 Google Chrome 的低 CPU 设备(Windows 10、2GB RAM、1GHz CPU)上速度极慢?

转载 作者:太空狗 更新时间:2023-10-29 17:01:42 26 4
gpt4 key购买 nike

我创建了一个简单的项目,其中安装了 Bootstrap 4 .但加载页面似乎需要 8-10 秒,CPU 使用率为 100%。 This is the configuration of my desktop on which CPU usage is high.

我正在通过 ng 服务的 AOT 运行项目 --aot。在低 CPU 桌面上进行测试时,加载页面需要 20-30 秒。这就是 Angular 的工作方式,或者我们可以改进它并使其在低 CPU 桌面上的一秒钟内加载 this configuration

This is a screenshot of the load timing of Angular on the low-CPU desktop.

脚本部分需要 6-7 秒才能加载页面,即使在使用 AOT 之后也是如此。这似乎很多。

Screenshot of the performance of my desktop machine with 8 GB RAM.

由于这种高 CPU 使用率,在低 CPU 设备上加载页面需要很长时间。

下面是我的 Angular JSON 文件:

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"testapp": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/testapp",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "testapp:build"
},
"configurations": {
"production": {
"browserTarget": "testapp:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "testapp:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"testapp-e2e": {
"root": "e2e/",
"projectType": "application",
"prefix": "",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "testapp:serve"
},
"configurations": {
"production": {
"devServerTarget": "testapp:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "testapp"
}

下面是我的包 JSON 文件:

{
"name": "testapp",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"bootstrap": "^4.1.3",
"core-js": "^2.5.4",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.11.0",
"@angular/cli": "~7.1.1",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}

this is command for servving using npm screenshot

this is my angular version screenshot

performance summary of the call tree details performance Bottomup of call tree performance call tree

最佳答案

我想知道该硬件配置上还有多少资源可以专注于运行此处的文件 -如果该机器运行的是 32 位 win10,则仍有空间,但如果它是 64 位,那么您就处于运行操作系统所需的绝对最低推荐资源。最重要的是,你有 Chrome,如果它是打开的,可能还有你的 IDE,这两者都被认为是该硬件的“笨重”。最后要提到的是使用 npm start 运行的开发服务器——所以有很多东西加起来,使系统很快就满了。剩余的 CPU 和 RAM 只能使用这么多(我想更多的阻塞和 GC 必须发生)。

如果您分享了您的(扩展的)windows 资源使用情况而不仅仅是 chrome,那可能会有所帮助。

测试构建的“生产”版本的方法:像其他人提到的那样运行 ng build --prod 。这不会生成源 map ,并且应该为全面高效的构建进行所有优化。运行 npm i -g http-server HTTP Server让您轻松地在本地提供静态资源运行 http-server ./dist/testapp -g导航到它指向的 URL 之一

-g 应该可以从中受益的 gzip 请求,但如果它们不够大则可能不会(其他人可能对此了解更多)。

所以这里我可能会有点热,但是,我个人不喜欢 Angular 中的 bootstrap,部分原因是实现。我觉得 Angular Material就是为它而生的;)如果你必须使用bs(我必须在工作中),很好用ng-bootstrap相反,但我发现在生态系统中还有其他选择非常有效。

至于 CPU 使用率,闲置时,Angular 应用程序选项卡的 CPU 使用率是 0.1%。当应用程序中开始发生事件时(如鼠标移动等),这将开始触发更改检测周期,这将占用大量 CPU 资源,但大部分问题都可以通过遵循某种 container component -> presentational component model 来解决。 (其中展示组件是 onPush)。我处理从小型到企业的不同规模的应用程序,并且对于绝大多数情况来说,由于模板/导出和嵌入,这个模型工作得很好。

关于angular - 为什么 Angular 7 框架在 Google Chrome 的低 CPU 设备(Windows 10、2GB RAM、1GHz CPU)上速度极慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53609108/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com