Skip to content

High Idle CPU Usage #10453

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

Open
phiresky opened this issue May 12, 2025 · 3 comments
Open

High Idle CPU Usage #10453

phiresky opened this issue May 12, 2025 · 3 comments
Assignees
Labels
Milestone

Comments

@phiresky
Copy link
Contributor

phiresky commented May 12, 2025

Describe the bug

The issue #10243 still persists even in the latest version:

cat go.js

require("@swc-node/register");

require("./test");

cat test.ts

class Test {
  a;
  b;
  c;
  d;
  e;
  f;
  g;
  h;
  i;
  j;
  k;
  l;
  m;
  n;
  o;
  p;
  q;
  r;
  s;
  t;
  u;
  v;
  w;
  x;
  y;
  z;
  constructor() {}
  hello() {
    return 'HELLO';
  }
}


setTimeout(() => {}, 20 * 1000); // to make the process run for 20 seconds

cat package.json

{
  "dependencies": {
    "@swc-node/register": "^1.10.10",
    "@swc/core": "^1.11.24"
  }
}

With 1.11.24:

/usr/bin/time -v node go.js
	Command being timed: "node go.js"
	User time (seconds): 2.73
	System time (seconds): 0.81
	Percent of CPU this job got: 17%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:20.32
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 156620
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 15834
	Voluntary context switches: 1125721
	Involuntary context switches: 133
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

With 1.10.8:

/usr/bin/time -v node go.js
	Command being timed: "node go.js"
	User time (seconds): 0.33
	System time (seconds): 0.07
	Percent of CPU this job got: 2%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:20.32
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 131564
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 14030
	Voluntary context switches: 175
	Involuntary context switches: 17
	Swaps: 0
	File system inputs: 0
	File system outputs: 0
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 0

As you can see, the process constantly uses 15% CPU (2.7s of CPU time in 20s) while in 1.10.8 it only uses 2% cpu (0.33s in 20s), all of which is during transpilation (0% during idle).

No swcrc file is present.

CPU usage seems to proportionally rise the more properties the class has.

Link to the code that reproduces this issue

https://play.swc.rs/?version=1.11.24&code=H4sIAAAAAAAAAx3Pyw6CQAwF0P18RXeAMWF0S3Rn4oLEDT%2BAUAR5DM50fBH%2B3bluTtqk7U1VNZTOUcFOaFFEZRa4ggrUgEEDbqAFHbiDHgxgBBMwYAYPYIEDAjx4ghd4gw%2F4%2FnPN5MT6SoyNE1pWJPIwGDShDtdYvJ0oOp%2Fy%2FBJhZVWrUsqxFN3IxkscZg%2FHsLulvaYN7bTWSUZpSmJoLHsmaZlmayoOv1s%2FUWMsRh2H9Nr9AO8kjXIVAQAA&config=H4sIAAAAAAAAA1VQOw6DMAzdOQXy3LUdeocewkoNCiIf2Y5UhLh7E0Io3ez38bO9dn0Pkxh49msucxORhfjsMyKLV%2FxkBHSJJIZtVLg1VqVQyol2ZKsEKPJIWkwk90MNcwhCGRtwFmpCRi9DYFcigQmNXsM5ebWumACTBodqDdSkFuWst8NyNZngIpPIf1SRoh%2Fnc4M6pjuWBhfeaSePT5Rr6wEP%2BIla2DkYrLyac3%2FD9gW9JRc9VQEAAA%3D%3D

SWC Info output

Operating System:
    Platform: linux
    Arch: x64
    Machine Type: x86_64
    Version: #1 SMP PREEMPT_DYNAMIC Thu, 13 Mar 2025 18:12:00 +0000
    CPU: (16 cores)
        Models: AMD Ryzen 7 7840U w/ Radeon  780M Graphics

Binaries:
    Node: 23.9.0
    npm: 11.3.0
    Yarn: 4.7.0
    pnpm: N/A

Relevant Packages:
    @swc/core: 1.11.24
    @swc/helpers: N/A
    @swc/types: 0.1.21
    typescript: 5.8.3

SWC Config:
    output: N/A
    .swcrc path: N/A

Next.js info:
    output: N/A

Expected behavior

No CPU usage

Actual behavior

High CPU usage on idle (even after transpilation done)

Version

1.11.24

Additional context

No response

@phiresky phiresky added the C-bug label May 12, 2025
@phiresky
Copy link
Contributor Author

Also note the Voluntary context switches: 1125721 and the higher memory usage.

@kdy1
Copy link
Member

kdy1 commented May 12, 2025

Please provide a standalone repository to reproduce this

@phiresky
Copy link
Contributor Author

phiresky commented May 12, 2025

Sure, here you go: https://gist.github.com/phiresky/e3d3dff24ff495552971dda945521b84

git clone https://gist.github.com/phiresky/e3d3dff24ff495552971dda945521b84
cd e3d3dff24ff495552971dda945521b84
npm install
node go.js

@kdy1 kdy1 added this to the Planned milestone May 13, 2025
@kdy1 kdy1 self-assigned this May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants