Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 12 RC 2 - Compilation is enormously slow and crashes on large build. #20713

Closed
14 tasks
ganySA opened this issue May 7, 2021 · 47 comments
Closed
14 tasks

Comments

@ganySA
Copy link

ganySA commented May 7, 2021

🐞 Bug report

Command (mark with an x)

  • new
  • [ x] build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • extract-i18n
  • run
  • config
  • help
  • version
  • doc

The build time for for angular 12 RC 2 is very slow - was also slow in RC0.
I have quite a big project with multiple lazy loaded modules. If i remove most of these and run its on a base set the compilation takes about 4-5minutes. When i include the lazy loaded modules it aborts after 5 minutes with a JavaScript heap memory.

With small code changes building/sealing takes 2-3 minutes.

[22280:00000215DB856250]  1371502 ms: Scavenge 2017.3 (2061.6) -> 2005.4 (2059.4) MB, 15.0 / 0.0 ms  (average mu = 0.373, current mu = 0.365) allocation failure
[22280:00000215DB856250]  1371545 ms: Scavenge 2020.7 (2061.9) -> 2008.2 (2059.4) MB, 13.9 / 0.0 ms  (average mu = 0.373, current mu = 0.365) allocation failure
[22280:00000215DB856250]  1371582 ms: Scavenge 2023.4 (2061.9) -> 2010.9 (2060.2) MB, 16.2 / 0.0 ms  (average mu = 0.373, current mu = 0.365) allocation failure


<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF6C293978D]
    1: StubFrame [pc: 00007FF6C29A56B5]
Security context: 0x011ffec408d1 <JSObject>
    2: LimitedMapView$blocklist0 [00000090B0991EF9] [C:\Development\R9-core\business-fed-r12\node_modules\sass\sass.dart.js:19422] [bytecode=000001A84E877181 offset=60](this=0x023f71f290a9 <Object map = 0000003DDD0B6219>,0x023c27a9bae9 <PrefixedMapView0 map = 00000237AEFEDC59>,0x03138c835f49 <UnmodifiableSetView map ...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF6C1D251EF napi_wrap+114271
 2: 00007FF6C1CCFE66 v8::base::CPU::has_sse+66630
 3: 00007FF6C1CD0C66 v8::base::CPU::has_sse+70214
 4: 00007FF6C24E522E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF6C24CD301 v8::SharedArrayBuffer::Externalize+833
 6: 00007FF6C239983C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
 7: 00007FF6C23A4A70 v8::internal::Heap::ProtectUnprotectedMemoryChunks+1312
 8: 00007FF6C23A1594 v8::internal::Heap::PageFlagsAreConsistent+3204
 9: 00007FF6C2396D93 v8::internal::Heap::CollectGarbage+1283
10: 00007FF6C239D624 v8::internal::Heap::GlobalSizeOfObjects+212
11: 00007FF6C23D344B v8::internal::StackGuard::HandleInterrupts+907
12: 00007FF6C211E459 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+7737
13: 00007FF6C293978D v8::internal::SetupIsolateDelegate::SetupHeap+546637
14: 00007FF6C29A56B5 v8::internal::SetupIsolateDelegate::SetupHeap+988789
15: 00007FF6C28BE73C v8::internal::SetupIsolateDelegate::SetupHeap+42748
16: 000000F5DDB88F1E
@ganySA
Copy link
Author

ganySA commented May 7, 2021

node --max_old_space_size=6144 ./node_modules/@angular/cli/bin/ng serve --open

Allows it to run longer than 5 minutes. Sitting at over 20 minutes at (phase: building)

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 7, 2021

Hi @ganySA,

Is there a way you can share the project even privately with the team? Or provide adding information such as cpu profile logs?. To generate a CPU profile you can use NG_BUILD_PROFILING env variable. Ex: NG_BUILD_PROFILING=1 ng build

Are you using JIT or AOT?

Thanks.

@ganySA
Copy link
Author

ganySA commented May 7, 2021

@alan-agius4 i have shared the repo with you.

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 10, 2021

Hi @ganySA,

Here are what I found;

  • It appears that the project was manually updated and not using ng update. This caused several migrations that need to be run to amend you project not to be executed.

The left your project is a broken state were now "development' builds are using "production" settings and hence cause increase in memory usage and slow rebuild times.

You can run the migration by using the below command (Note, don't run the ng-update command multiple times as one of the migrations is non-idempotent)

ng update @angular/cli --migrate-only --from 11 --to 12
  • From the CPU profile, I can also see that dart-sass is taking most of the time of the compilation, one of your files tailwind.scss contains 121836 lines with a size of 2.44mb. Realistically I don't think SASS can handle files this big and I am not surprised with the amount of memory needed.

@alan-agius4 alan-agius4 removed the needs: more info Reporter must clarify the issue label May 10, 2021
@ganySA
Copy link
Author

ganySA commented May 10, 2021

Hi Alan

Thank i will try the migrate command. Tailwind is a modern CSS framework that i believe angular CLI supports?
Referencing this issue #20015 where tailwind support is noted. I suspect that if the configuration is broken and it is running a full build then its trying to remove unused SCSS from tailwind hence for production CSS is minimised.

What is interesting is that this does not happen on v11 but this could as you point out be due to the build. I will do the upgrade and give it a go.

Thanks for taking the time to investigate.

@alan-agius4 alan-agius4 self-assigned this May 10, 2021
@alan-agius4
Copy link
Collaborator

Hi Alan

Thank i will try the migrate command. Tailwind is a modern CSS framework that i believe angular CLI supports?
Referencing this issue #20015 where tailwind support is noted. I suspect that if the configuration is broken and it is running a full build then its trying to remove unused SCSS from tailwind hence for production CSS is minimised.

What is interesting is that this does not happen on v11 but this could as you point out be due to the build. I will do the upgrade and give it a go.

Thanks for taking the time to investigate.

In the reproduction tailwinds is not used, because there is no tailwind configuration in the root of the project. The CLI looks for tailwind.config.js in the project root with a fallback to the workspace root.

const tailwindConfigFile = 'tailwind.config.js';
let tailwindConfigPath;
for (const basePath of [wco.projectRoot, wco.root]) {
const fullPath = path.join(basePath, tailwindConfigFile);
if (fs.existsSync(fullPath)) {
tailwindConfigPath = fullPath;
break;
}
}

@ganySA
Copy link
Author

ganySA commented May 10, 2021

I have these under /configs/ and for some reason this has worked - i was using a custom builder.
I have made all the changes as you recommended but these do not seem to work.
The issue for me right now is that if these errors do not occur in 11 but manifest in 12 i suspect there is something else taking place.
I have placed the tailwind configuration file i have into the base - it does not make a different. Tailwind processing should only take place with production flag. Is it possible that it does it regardless?

@alan-agius4
Copy link
Collaborator

I have placed the tailwind configuration file i have into the base - it does not make a different. Tailwind processing should only take place with production flag. Is it possible that it does it regardless?

I don't see any tailwind.config.js in the root of your project. Did you forget to push?

@ganySA
Copy link
Author

ganySA commented May 10, 2021

I have reset my configuration to a simple configuration from a new angular 12 project and slowly added back settings.
I can further add that it seems a lot happier when i remove my styles folder from preprocessors
"stylePreprocessorOptions": {
"includePaths": [
"src/@calendar5/styles"
]
},

Even with a basic 'reset' configuration build takes about 4 minutes. I have not pushed will do so now.
I would say on 11 it takes about 1minute.

@ganySA
Copy link
Author

ganySA commented May 10, 2021

Pushed updates.

@alan-agius4
Copy link
Collaborator

I did notice that due to import path src/@calendar5/styles the build is slower this appears to be related to @import '~@angular/material/theming'; in treo.scss.

This is above, is import is quite expensive and in your case it needs to be resolved around 65 times because you import this file that many times. Previously @angular/material/theming was a flattened into a single file not now it appears that something in version 12 changed is spit among a large number of files which indeed in this particular case is causing a significant performance degradation. //cc @jelbourn

Ps: I see don't see the tailwind.config.js configuration file.

@ganySA
Copy link
Author

ganySA commented May 10, 2021

The tailwind.config.js file is in the root.

@ganySA
Copy link
Author

ganySA commented May 10, 2021

I did notice that due to import path src/@calendar5/styles the build is slower this appears to be related to @import '~@angular/material/theming'; in treo.scss.

This is above, is import is quite expensive and in your case it needs to be resolved around 65 times because you import this file that many times. Previously @angular/material/theming was a flattened into a single file not now it appears that something in version 12 changed is spit among a large number of files which indeed in this particular case is causing a significant performance degradation. //cc @jelbourn

Ps: I see don't see the tailwind.config.js configuration file.

Glad we seem to have found the issue!

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 10, 2021

In your tailwind configuration you have set purge to true, this means that purging will done also for development builds which is undesired as it will slow down the build considerably.

module.exports = {
    purge: {
      enabled: true,
      content: ['./src/**/*.html', './src/**/*.ts'],
    },
    // ...
  }

Purging should be only enabled during builds for production, using TAILWIND_MODE environment variable.

    enabled: process.env.TAILWIND_MODE === 'build',

see #20015 (comment) for more context.

With regards to @angular/material/theming, in version 12 Material switched to a new SASS module system, switching the @import to @use should speed up things quite a lot. That said, in your case this is not the case because of the large number of times it is being imported. Therefore, I suggest that you only import the theme when needed instead of every SASS compilation which in your case you have around 70 times as each component is a different SASS compilation.

@kyliau kyliau pinned this issue May 10, 2021
@alan-agius4
Copy link
Collaborator

Following some more investigation, you should get a better performance if you use the new entry-point from @angular/material using the new theming API, which should be faster.

To run the code migration in RC 2 you can use;

ng g @angular/material:themingApi

In RC 3 or later, this migration will run automaticity when updating @angular/material using ng update @angular/material.

@ganySA
Copy link
Author

ganySA commented May 11, 2021

Hi

Thank you for your response and instructions. I have made the above changes and now the build does complete.
However comparatively to version 11 still very slow.

Build at: 2021-05-11T04:37:13.071Z - Hash: df562f020e16595dacaf - Time: 158221ms
Build at: 2021-05-11T04:37:56.654Z - Hash: f1a5d4f5bdfeb0d8b006 - Time: 40188ms

After a number of code changes - i still receive a Javascript heap exception.
[50860:0000012BBF3B4700] 6704986 ms: Mark-sweep 2010.2 (2085.3) -> 2010.1 (2054.3) MB, 656.5 / 0.1 ms (average mu = 0.248, current mu = 0.000) last resort GC in old space requested
[50860:0000012BBF3B4700] 6705738 ms: Mark-sweep 2010.1 (2054.3) -> 2010.0 (2054.3) MB, 751.5 / 0.1 ms (average mu = 0.148, current mu = 0.000) last resort GC in old space requested

<--- JS stacktrace --->

==== JS stack trace =========================================

    0: ExitFrame [pc: 00007FF6C293978D]
Security context: 0x03b48d6008d1 <JSObject>
    1: set [000003B48D60A791](this=0x0148098b1ec1 <Map map = 000003F4E4540899>,0x03b128cc6bc1 <String[113]: C:\Development\R9-core\business-fed-r12\node_modules\@angular\material\progress-spinner\progress-spinner.d.ts.map>,0x013374a345d1 <Object map = 000000F69F539879>)
    2: addFileTimestamps [00000186F1D4F339] [C:\Development\R9-core\business-fed-r12\no...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 00007FF6C1D251EF napi_wrap+114271
 2: 00007FF6C1CCFE66 v8::base::CPU::has_sse+66630
 3: 00007FF6C1CD0C66 v8::base::CPU::has_sse+70214
 4: 00007FF6C24E522E v8::Isolate::ReportExternalAllocationLimitReached+94
 5: 00007FF6C24CD301 v8::SharedArrayBuffer::Externalize+833
 6: 00007FF6C239983C v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1436
 7: 00007FF6C2395509 v8::internal::Heap::AddRetainedMap+2713
 8: 00007FF6C23B674B v8::internal::Factory::NewFixedArrayWithFiller+107
 9: 00007FF6C23AF717 v8::internal::Factory::InternalizeString<unsigned short>+471
10: 00007FF6C21EC2EB v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::Allocate+123
11: 00007FF6C21EE43B v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::Rehash+59
12: 00007FF6C21ED3CA v8::internal::OrderedHashTable<v8::internal::OrderedHashMap,2>::EnsureGrowable+90
13: 00007FF6C21386E2 v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+114882
14: 00007FF6C293978D v8::internal::SetupIsolateDelegate::SetupHeap+546637
15: 00007FF6C28FE3EA v8::internal::SetupIsolateDelegate::SetupHeap+304042

Just a side note -
lodash-es now complains about imports (causing all sorts of little issues).

@alan-agius4
Copy link
Collaborator

I have compiled a list of SCSS files in your project, with the duration each of them takes to compile.

File Compilation Duration
src/app/modules/components/confirmation-dialog/confirmation-dialog.component.scss 198.585ms
src/app/modules/components/business-selector/business-selector.component.scss 226.805ms
src/app/modules/components/calendar-view-selector/calendar-view-selector.component.scss 113.614ms
src/app/modules/components/appointment-tags/appointment-tag.component.scss 116.932ms
src/app/app.component.scss 605.148ms
src/app/layout/layout.component.scss 605.658ms
src/app/modules/components/location-list/location-list.component.scss 190.462ms
src/app/modules/components/loading-indicator/loading-indicator.component.scss 181.293ms
src/app/modules/components/status-reason-selector/status-reason.component.scss 312.058ms
src/app/modules/components/time-input/time-input.component.scss 213.569ms
src/app/modules/components/calendar-navigator/calendar-navigator.component.scss 382.951ms
src/app/modules/components/calendar-datepicker-mobile/calendar-datepicker-mobile.component.scss 262.115ms
src/app/modules/components/staff-schedule-online/staff-schedule-online.component.scss 279.454ms
src/app/modules/components/business-image-upload/business-image-upload.component.scss 330.490ms
src/app/modules/components/telephone-input/telephone-input.component.scss 706.046ms
src/app/modules/components/staff-list/staff-list.component.scss 158.073ms
src/app/modules/components/staff-schedule-online/new-popup/new-popup.component.scss 326.035ms
src/app/modules/components/service-list/service-list.component.scss 332.479ms
src/styles/vendors.scss 151.641ms
src/styles/styles.scss 415.450ms
src/app/modules/secure/calendar/scheduler/scheduler.component.scss 20.837ms
src/app/modules/secure/client/client.component.scss 45.149ms
src/app/modules/secure/calendar/calendar.component.scss 55.514ms
src/app/modules/secure/user/user.component.scss 15.825ms
src/app/modules/secure/notifications/notification.component.scss 65.766ms
src/app/modules/secure/business/business.component.scss 70.902ms
src/app/modules/secure/calendar/edit-appointment/edit-appointment.component.scss 93.290ms
src/app/modules/secure/calendar/calendar-popup-new/calendar-popup-new.component.scss 206.218ms
src/app/modules/secure/calendar/calendar-settings/calendar-settings.component.scss 97.512ms
src/app/modules/secure/calendar/date-selector/date-selector.component.scss 362.114ms
src/app/modules/secure/calendar/calendar-popup/calendar-popup.component.scss 435.449ms
src/app/modules/secure/calendar/date-selector-mobile/date-selector-mobile.component.scss 133.737ms
src/app/modules/secure/calendar/duplicate-check/duplicate-check.component.scss 108.342ms
src/app/modules/secure/calendar/client-mini-details/client-mini-details.component.scss 149.841ms
src/app/modules/secure/calendar/color-picker/color-picker.component.scss 125.083ms
src/app/modules/secure/calendar/calendar-datepicker/calendar-datepicker.component.scss 117.458ms
src/app/modules/secure/user/business-hours/business-hours.component.scss 21.889ms
src/app/modules/secure/locations/add/location.add.component.scss 23.833ms
src/app/modules/secure/staff/add/staff.add.component.scss 21.454ms
src/app/modules/secure/locations/edit/location.edit.component.scss 26.471ms
src/app/modules/secure/business/business-hours/business-hours.component.scss 16.122ms
src/app/modules/secure/staff/edit/staff.edit.component.scss 21.279ms
src/app/modules/secure/notifications/smsconfig/sms-config.component.scss 151.573ms
src/app/modules/secure/notifications/notification-setup/notifications-setup.component.scss 152.955ms
src/app/modules/secure/services/add/services.add.component.scss 65.949ms
src/app/modules/secure/services/edit/services.edit.component.scss 79.619ms
src/app/modules/secure/notifications/emailconfig/email-config.component.scss 92.453ms
src/app/modules/secure/sharing/add/sharing.add.component.scss 52.050ms
src/app/modules/secure/sharing/edit/sharing.edit.component.scss 52.332ms
src/app/modules/secure/tags/add/tags.add.component.scss 83.224ms
src/app/modules/secure/tags/edit/tags.edit.component.scss 89.021ms
src/app/modules/secure/invoice/list/list.component.scss 71.595ms
src/app/modules/secure/invoice/wizard/wizard.invoice.new.component.scss 93.790ms
src/app/modules/secure/invoice/print/invoice.print.component.scss 119.982ms
src/app/modules/secure/invoice/add/invoice.add.component.scss 131.744ms
src/app/modules/secure/invoice/edit/invoice.edit.component.scss 169.018ms
src/app/modules/secure/dashboards/finance/finance.component.scss 38.295ms
src/app/modules/secure/dashboards/analytics/analytics.component.scss 37.294ms
src/app/modules/components/app-avatar-icon/avatar-icon/avatar-icon.component.scss 145.442ms
src/app/modules/secure/client/tabs/client-details-tab/client-details-tab.component.scss 163.914ms
src/app/modules/secure/business/tabs/billing/billing.component.scss 34.583ms
src/app/modules/components/invoice-components/invoice-status-chip/invoice-status-chip.component.scss 24.063ms
src/app/modules/components/invoice-components/invoice-status-selector/invoice-status-selector.component.scss 14.705ms
src/app/modules/secure/invoice/components/invoice-line-items-medical/invoice-line-items-medical.component.scss 14.502ms
src/app/modules/secure/invoice/components/invoice-line-items-standard/invoice-line-items-standard.component.scss 100.924ms
src/app/modules/secure/user/tabs/basic/user-basic-tab.component.scss 33629.968ms
src/app/modules/secure/business/tabs/basic/basic.component.scss 33630.795ms
src/app/modules/landing/home/home.component.scss 38404.535ms
src/app/modules/auth/forgot-password/forgot-password.component.scss 39747.032ms
src/app/modules/auth/reset-password/reset-password.component.scss 39744.085ms
src/app/modules/auth/unlock-session/unlock-session.component.scss 39297.822ms
src/app/modules/auth/zoom-register/zoom-register.component.scss 38550.229ms
src/app/modules/secure/contacts/contacts.component.scss 38307.074ms
src/app/modules/secure/locations/locations.component.scss 38105.035ms
src/app/modules/secure/staff/staff.component.scss 38104.543ms
src/app/modules/secure/services/services.component.scss 38053.263ms
src/app/modules/secure/sharing/sharing.component.scss 38052.244ms
src/app/modules/secure/invoice/invoice.component.scss 37910.515ms
src/app/modules/secure/tags/tags.component.scss 37874.639ms
src/app/modules/auth/confirmation-required/confirmation-required.component.scss 39770.821ms
src/app/modules/auth/sign-up/sign-up.component.scss 39420.359ms
src/app/modules/auth/sign-out/sign-out.component.scss 39345.798ms
src/app/modules/auth/sign-in/sign-in.component.scss 39348.430ms
src/app/layout/layouts/empty/empty.component.scss 42415.832ms
src/app/modules/pages/coming-soon/coming-soon.component.scss 38610.130ms
src/app/modules/components/client-search-box/client-search-box.component.scss 40448.352ms
src/app/modules/secure/calendar/search-box/search-box.component.scss 36134.033ms
src/app/modules/secure/example/example.component.scss 38421.690ms
src/app/modules/secure/calendar/calendar-selector/calendar-selector.component.scss 36248.072ms
src/app/modules/pages/maintenance/maintenance.component.scss 38570.811ms
src/app/modules/pages/errors/error-404/error-404.component.scss 38554.954ms
src/app/modules/pages/errors/error-500/error-500.component.scss 38553.552ms
src/app/modules/secure/client/tabs/messages/messages.component.scss 34230.820ms
src/app/modules/secure/business/tabs/features/features.component.scss 33859.935ms
src/app/modules/secure/calendar/client-fields/client-fields.component.scss 36342.120ms
src/app/modules/secure/client/tabs/appointments/appointments.component.scss 34247.793ms
src/app/modules/pages/help-center/guides/category/category.component.scss 38687.341ms
src/@calendar5/components/card/card.component.scss 42434.489ms
src/app/modules/secure/dashboards/crypto/crypto.component.scss 34497.085ms
src/app/modules/pages/help-center/faqs/faqs.component.scss 38779.186ms
src/app/modules/secure/invoice/components/add-invoice-item/add-invoice-item.component.scss 33814.726ms
src/app/modules/secure/calendar/client-form-search/client-form-search.component.scss 36463.357ms
src/app/modules/pages/help-center/support/support.component.scss 38808.181ms
src/app/modules/components/status-reason-selector/status-reason.dialog.component.scss 42313.379ms
src/app/modules/pages/help-center/guides/guides.component.scss 38910.350ms
src/@calendar5/components/navigation/horizontal/horizontal.component.scss 42559.517ms
src/app/modules/secure/calendar/recurrence/recurrence.component.scss 36499.784ms
src/app/layout/layouts/vertical/classic/classic.component.scss 42690.839ms
src/app/modules/pages/help-center/guides/guide/guide.component.scss 38959.869ms
src/app/modules/pages/help-center/help-center.component.scss 39065.089ms
src/app/modules/components/invoice-components/invoice-list/invoice-list.component.scss 34193.163ms
src/app/modules/secure/contacts/list/list.component.scss 38443.885ms
src/app/modules/secure/tags/list/list.component.scss 35588.145ms
src/app/modules/secure/locations/list/list.component.scss 36520.808ms
src/app/layout/layouts/vertical/basic/basic.component.scss 42850.519ms
src/app/modules/secure/services/list/list.component.scss 35997.477ms
src/app/modules/secure/sharing/list/list.component.scss 35789.004ms
src/app/modules/secure/staff/list/list.component.scss 36378.323ms
src/app/layout/common/shortcuts/shortcuts.component.scss 42949.068ms
src/app/layout/common/notifications/notifications.component.scss 43029.700ms
src/app/layout/common/messages/messages.component.scss 43256.641ms
src/app/modules/pages/pricing/simple/simple.component.scss 39143.596ms
src/app/modules/pages/pricing/single/single.component.scss 39133.973ms
src/app/modules/pages/pricing/modern/modern.component.scss 39195.011ms
src/app/layout/common/search/search.component.scss 43135.907ms
src/app/modules/pages/pricing/table/table.component.scss 39152.263ms
src/app/layout/common/user/user.component.scss 43100.358ms
src/app/modules/secure/contacts/details/details.component.scss 38779.435ms
src/@calendar5/components/navigation/vertical/vertical.component.scss 43053.855ms
src/@calendar5/components/message/message.component.scss 43156.939ms
src/@calendar5/styles/main.scss 48927.366ms

The slowest compilations have in common that they all depend on @angular/material new theming api, extract from a transitive file.

@use '~@angular/material' as mat;
@function treo-light-theme($primary-palette, $accent-palette, $warn-palette) {

    // Generate the Angular Material theme
    $angular-material-theme: mat.define-light-theme($primary-palette, $accent-palette, $warn-palette);

    // Modify and return the theme
    @return _treo-modify-angular-material-theme-colors($angular-material-theme);
}

@function treo-dark-theme($primary-palette, $accent-palette, $warn-palette) {

    // Generate the Angular Material theme
    $angular-material-theme: mat.define-dark-theme($primary-palette, $accent-palette, $warn-palette);

    // Modify and return the theme
    @return _treo-modify-angular-material-theme-colors($angular-material-theme);
}

@function treo-palette($palette, $default: 500, $lighter: 100, $darker: 700, $text: $default) {
    @return mat.define-palette(map-get($treo-colors, $palette), $default, $lighter, $darker, $text);
}

Locally the timings are a bit better, which I do expect on Windows (Which appears to be your OS) IO is slower.

Build at: 2021-05-11T11:05:17.333Z - Hash: abea6554978740e91cc4 - Time: 93344ms

I tried try to force a couple of re-builds, what I did was to amend src/app/modules/secure/sharing/list/list.component.scss, each rebuilt took around 2.9s~3.1s, I tried about 10 times, and the memory consumptions stayed pretty consistent.

Can you please provide;

  • output of ng v
  • the exact steps / files that you amended to cause the above errors
  • which command are you using?

@ganySA
Copy link
Author

ganySA commented May 11, 2021

I suspect the new theming API is the challenge. Unless i refactor the entire project it will not be simple to remove given how its architectured. This is still quite a major regression.

I ng v

Angular CLI: 12.0.0-rc.3
Node: 12.18.1
Package Manager: npm 6.14.11
OS: win32 x64

Angular: 12.0.0-rc.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.0-rc.3
@angular-devkit/build-angular   12.0.0-rc.3
@angular-devkit/core            12.0.0-rc.3
@angular-devkit/schematics      12.0.0-rc.3
@angular/cdk                    12.0.0-rc.2
@angular/flex-layout            11.0.0-beta.33
@angular/material               12.0.0-rc.2
@schematics/angular             12.0.0-rc.3
rxjs                            6.6.7
typescript                      4.2.4

Under CLI RC3

Build at: 2021-05-11T18:39:54.431Z - Hash: 6736c7ce908561b778da - Time: 136206ms
Build at: 2021-05-11T18:40:28.316Z - Hash: c45791f7ad1a35c6b5fa - Time: 30612ms

@ganySA
Copy link
Author

ganySA commented May 11, 2021

Should i log a query under @angular/material ?

@alan-agius4
Copy link
Collaborator

@clydin is working on improving the SASS compilation times in general by offloading the compilation to a worker and changing the SASS compilation asynchronous to synchronous. You can see this PR #20740.

Dart-sass is synchronous can be twice as fast. From initial testing I did see some good improvements in your project, and the build time did improve by around 15%. The compilation of your application took around 81675ms.

Regarding the OOM issues, I still didn't receive answer for the following questions. I did trigger multiple rebuilds and memory usage did stay consistent;

  • the exact steps / files that you amended to cause the above errors
  • which command are you using?

Should i log a query under @angular/material ?

I think this would be useful, so that it's also tracked in their repo.

@ganySA
Copy link
Author

ganySA commented May 12, 2021

Sorry taken some time to work out best way to emulate a crash.
Steps to reproduce the crash on compilation:

  1. ng serve
  2. open app in browser
  3. edit app.routing.ts as follows:
  4. comment out lines 171 to 183 and let it compile (a few lazy loaded modules)
  5. uncomment back lines 171 to 183 and let it compile -- it crashes on my end

sometimes you need to do step 3 and 4 twice.

@ganySA
Copy link
Author

ganySA commented May 14, 2021

@alan-agius4 did you manage to reproduce the OOM crash?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented May 17, 2021

Yeah, I did but so far had little luck getting to the bottom of it. Let's continue tracking the OOM in #20801 please.

@joelcoxokc
Copy link

joelcoxokc commented May 19, 2021

I thought I should make a comment here.

I am not using tailwind.

My SCSS bundles are not large at all sitting at 267KB

I am still having the HEAP size issues, and am only able to develop by setting the NODE_OPTIONS env variable referenced above.

The build times in my github actions have nearly tripled since I updated to 12.

I am using nx.dev with a mono repo...

@alan-agius4
Copy link
Collaborator

Yesterday release (12.0.1) contains several performance improvements. Please give it a try!

@NateRadebaugh
Copy link

12.0.1 didn't improve my project's build times either. Sometimes the CI fails with a OOM error after 5 minutes and other times it takes ~25 minutes to compile when it used to compile in ~12 minutes. It sounds like the regression in around the SCSS integration?

@clydin
Copy link
Member

clydin commented May 24, 2021

@NateRadebaugh Are those production or development build times?

Sass processing was greatly improved in 12.0.1. However, in an unrelated change, the CSS optimizer plugin was also switched to use the Webpack provided plugin. This plugin has the unfortunate behavior of potentially creating an unbounded number of worker threads. In the event of this happening, performance can become significantly worse due to the large volume of context switches and can also lead to memory problems. A fix (PR #20886) to limit the number of worker threads that the Webpack plugin can use has been merged and will be included in 12.0.2.

@NateRadebaugh
Copy link

NateRadebaugh commented May 24, 2021

@clydin it looks like my issue may be the same as this thread or related to #20792

My issue with for production builds in the CI, not development builds. In fact, local production builds are not impacted as much, but the CI builds are 2x.

@simeyla
Copy link

simeyla commented May 28, 2021

@alan-agius4 I updated with ng update and was still seeing very (frankly) depressingly longer serve times.

Running:

ng update @angular/cli --migrate-only --from 11 --to 12

took me back down from 120 seconds to 74 seconds which is around where I was before.

However it turns out that if you run the migrations multiple time it can actually disable aot which then gives the illusion of speeding everything up. The migrations file from Angular 11 to 12 will remove the aot setting if it is set to true (because it removes redundant default values by design). If you then run it a second time it will actually set the aot value to false (due to a bug).

@alan-agius4
Copy link
Collaborator

@ganySA how is the performance in 12.0.3 and are the OOM issues resolved?

@NateRadebaugh
Copy link

Updating to 12.0.3 did not have any improvement for me.

@joelcoxokc
Copy link

joelcoxokc commented Jun 10, 2021

@alan-agius4 very minor improvement for me.
My build times + ng lint
version 11 --- 7 minutes
version 12.0.1 --- 26 minutes
version 12.0.3 --- 23 minutes

I have a very large mono-repo using nx.dev so excuse the dramatic numbers

@clydin
Copy link
Member

clydin commented Jun 10, 2021

@joelcoxokc Are those all production builds?

@joelcoxokc
Copy link

@clydin yes. That is running ng build with aot turned on.
If I remove ng lint the time for production build on 12.0.3 is 9 minutes.
My production build times without ng lint on version 11 was 3-4 minutes

@clydin
Copy link
Member

clydin commented Jun 10, 2021

If you have some time, can you try running them with the environment variable NG_BUILD_CACHE=0?

@hadrien-toma

This comment has been minimized.

@alan-agius4

This comment has been minimized.

@alan-agius4

This comment has been minimized.

@joelcoxokc
Copy link

@clydin I am not quite sure what that did.
I added that to my github action and now my build only takes 4.5 minutes.

I also removed it and my build is still sitting at 4.5 minutes.
I don't know if this was a github action issue or not.

If I run ngcc after my npm install the build hits about 10 minutes. But I think that is expected with ngcc.

@NateRadebaugh
Copy link

NateRadebaugh commented Jun 12, 2021

What I did to get around this issue:

  1. Make sure git is set up and everything is checked in.
  2. Delete the existing app folder/contents
  3. Using angular CLI to create a new blank app in the spot where the old one was
  4. Looking at the git status (eg on vs code) One by one, revert the deletes for non-build related files like your app components, services, directives, pipes, etc.
  5. Slowly restore everything except the custom HRM config, angular.json, tsconfig, and package.json/lock files. (Manually npm install dependencies until your package.json is mostly back to how it was)
    • Custom HMR setups like @angularclass/hmr seem to conflict with the "out of the box" supported --hmr in the latest version of angular
  6. Rebuild. Somehow magically the updates to your tsconfig and angular.json has made the build take ~4 minutes.

Angular 11: 8 minutes
Ng update to 12: 24 minutes
Recreate as 12: 4 minutes

Why/how? My guess is the automatic migrations aren't working correctly, and so far what others are reporting is that the cache stuff in 12 with webpack 5 is busted with the migrations as is. Migrations also aren't able to detect unsupported dependencies.

@alan-agius4
Copy link
Collaborator

@NateRadebaugh, are you using third party builders?

@NateRadebaugh

This comment has been minimized.

@alan-agius4
Copy link
Collaborator

You need to opt-in into HMR. Using —hmr.

if you are experiencing performance issues please share a reproduction and/or CPU profile, unfortunately without any of these we will not be able to Investigate.

@NateRadebaugh
Copy link

Thanks @alan-agius4 I have confirmed using the following script did work for HMR:

"start": "ng serve --hmr --configuration development",

And to follow up, no I'm not using any other custom bundlers. Thanks!

@Yohandah
Copy link

Yohandah commented Jun 16, 2021

ng build --prod was working in v11, it doesn't in v12 for me as well. This is quite a huge project as well, I find it disappointing that I can't upgrade to updated versions of Angular

| Generating browser application bundles (phase: building)...  babel:config:config-chain Ignored 'C:\\Users\\x\\x\\x\\x\\frontend\\node_modules\\css-loader\\dist\\runtime\\api.js' because it matched one of [ [Function (anonymous)] ] from
 'C:\\Users\\x\\x\\x\\x\\frontend' +579ms
- Generating browser application bundles (phase: sealing)...events.js:353
      throw er; // Unhandled 'error' event
      ^

Error [ERR_WORKER_OUT_OF_MEMORY]: Worker terminated due to reaching memory limit: JS heap out of memory
    at Worker.[kOnExit] (internal/worker.js:247:26)
    at Worker.<computed>.onexit (internal/worker.js:177:20)
Emitted 'error' event on Worker instance at:
    at Worker.[kOnExit] (internal/worker.js:247:12)
    at Worker.<computed>.onexit (internal/worker.js:177:20) {
  code: 'ERR_WORKER_OUT_OF_MEMORY'
}
[ERROR] An error occurred while running subprocess ng.

        ng.cmd run app:build:production --verbose exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.
  ionic:utils-process onBeforeExit handler: 'process.exit' received +0ms
  ionic:utils-process onBeforeExit handler: running 1 functions +0ms
  ionic:utils-process error while killing process tree for 11004: Error: Command failed: taskkill /pid 11004 /T /F
  ionic:utils-process Erreur�: le processus "11004" est introuvable.
  ionic:utils-process 
  ionic:utils-process     at ChildProcess.exithandler (child_process.js:319:12)
  ionic:utils-process     at ChildProcess.emit (events.js:376:20)
  ionic:utils-process     at maybeClose (internal/child_process.js:1055:16)
  ionic:utils-process     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  ionic:utils-process   killed: false,
  ionic:utils-process   code: 128,
  ionic:utils-process   signal: null,
  ionic:utils-process   cmd: 'taskkill /pid 11004 /T /F'
  ionic:utils-process } +162ms
  ionic:utils-process onBeforeExit handler: error from function: Error: Command failed: taskkill /pid 11004 /T /F
  ionic:utils-process Erreur�: le processus "11004" est introuvable.
  ionic:utils-process 
  ionic:utils-process     at ChildProcess.exithandler (child_process.js:319:12)
  ionic:utils-process     at ChildProcess.emit (events.js:376:20)
  ionic:utils-process     at maybeClose (internal/child_process.js:1055:16)
  ionic:utils-process     at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  ionic:utils-process   killed: false,
  ionic:utils-process   code: 128,
  ionic:utils-process   signal: null,
  ionic:utils-process   cmd: 'taskkill /pid 11004 /T /F'
  ionic:utils-process } +2ms
  ionic:utils-process processExit: exiting (exit code: 1) +1ms
npm ERR! code ELIFECYCLE
npm ERR! errno 1

Angular CLI: 12.0.4
Node: 14.17.0
Package Manager: npm 6.14.13
OS: win32 ia32

Angular: 12.0.4
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, localize, material
... platform-browser, platform-browser-dynamic, pwa, router
... service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1200.4
@angular-devkit/build-angular   12.0.4
@angular-devkit/core            12.0.4
@angular-devkit/schematics      12.0.4
@schematics/angular             12.0.4
rxjs                            6.6.7
typescript                      4.2.4

@alan-agius4
Copy link
Collaborator

Lets continue tracking this in #20792 and #20801.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants