Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Conversation

@jooskim
Copy link
Contributor

@jooskim jooskim commented Aug 21, 2021

Internal testing on VMware Cloud UI revealed that there are certain
conditions that could impact the performance of the Angular change
detection system, or any other frontend frameworks that rely on the
Event Loop of the JS engine.

Currently every message being sent via the sendResponseMessage(),
sendResponseMessageWithId() or
sendResponseMessageWithIdAndVersion() method is scheduled as a macro
task, which means send message logic shares CPU resources with other
macro tasks like DOM painting or other event handling. This way of
sharing the CPU single thread with other tasks usually is benign enough
not to cause much trouble if any.

However, if 1) the send message method is called in rapid succesion,
and 2) each macro task triggers a compute-intensive task such as a
complete re-render of the view like Angular with default change
detection strategy does, the UI will experience a significant
performance hit that looks like a tight loop that could be observed
in the Chrome Inspect Panel.

A sensible solution to the problem is to buffer the payload by a
certain interval and scheduling the macro tasks by chunks not by
every single entry. By doing this it will limit the impact to the
CPU because now the change detection will happen only as frequently
as the buffer is flushed.

See the attached benchmarks for comparisons in CPU utilization.

Signed-off-by: Josh Kim [email protected]

@jooskim jooskim marked this pull request as draft August 21, 2021 07:34
@jooskim
Copy link
Contributor Author

jooskim commented Aug 21, 2021

1_annotated
2_annotated
3_annotated
side-by-side

Internal testing on VMware Cloud UI revealed that there are certain
conditions that could impact the performance of the Angular change
detection system, or any other frontend frameworks that rely on the
Event Loop of the JS engine.

Currently every message being sent via the `sendResponseMessage()`,
 `sendResponseMessageWithId()` or
`sendResponseMessageWithIdAndVersion()` method is scheduled as a macro
task, which means send message logic shares CPU resources with other
macro tasks like DOM painting or other event handling. This way of
sharing the CPU single thread with other tasks usually is benign enough
not to cause much trouble if any.

However, if 1) the send message method is called in rapid succesion,
and 2) each macro task triggers a compute-intensive task such as a
complete re-render of the view like Angular with default change
detection strategy does, the UI will experience a significant
performance hit that looks like a tight loop that could be observed
in the Chrome Inspect Panel.

A sensible solution to the problem is to buffer the payload by a
certain interval and scheduling the macro tasks by chunks not by
every single entry. By doing this it will limit the impact to the
CPU because now the change detection will happen only as frequently
as the buffer is flushed.

See the attached benchmarks for comparisons in CPU utilization.

Signed-off-by: Josh Kim <[email protected]>
@jooskim jooskim force-pushed the topic/kjosh/buffered-send branch from 0f3793d to 924442c Compare August 24, 2021 04:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant