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

profile with xcode instruments #910

Closed
xusd320 opened this issue Feb 4, 2024 · 2 comments
Closed

profile with xcode instruments #910

xusd320 opened this issue Feb 4, 2024 · 2 comments
Labels
question Further information is requested

Comments

@xusd320
Copy link
Contributor

xusd320 commented Feb 4, 2024

Problem

Mako is a both I/O intensive and CPU intensive program, directly reading the source codes and writing outputs with std::fs will cause the main compile blocking.

Analysis

TODO: Use tools like Xcode Instruments to track the I/O syscalls.

Solution

Let I/O and compiler run in individual thread pool.

@xusd320
Copy link
Contributor Author

xusd320 commented Feb 23, 2024

Performance analysis with instruments

File Activity

  • Cold build (without os kernel fs cache):

    • fs read:
      those long timing fs reads and fs stats are been invoked by mako::load::read_content and nodejs_resolver.
      image

      • in mako::load::read_content, there is only a call of std::fs::read_to_end,maybe no better implements. The crate memmap2 is a choice, but also will leads to some risks.
      image
      • a lots of invalid readlink and stat calls invoked by nodejs_resolver, why ?
      image image
    • fs write:
      fs write is fast enough when building examples/with-antd, maybe no need to optimize. Not test on heavy project.
      image

  • Hot build:
    Still spends a lot of time on fs reads
    image

Timing Profiler:

System Trace:

  • Threads:
    Threads are not well load balanced,  a lot of blocking occurs
    image
    image
    What's those tokio workers doing for?

  • Sys calls:

    • Those are spending on rayon and tokio threads.
      image

    • Those are spending on mako::load::read_content and nodejs_resolver. About nodejs_resolver probleam, test it again after switch to oxc-resolver.
      image

    • Mutex
      image

@xusd320
Copy link
Contributor Author

xusd320 commented Mar 5, 2024

tree shaking 和 generate 在主线程中串行执行,在构建 example/with-antd 时,这两个阶段各占总耗时的 1/4

image image

@xusd320 xusd320 changed the title RFC: Too much blocking I/O maybe a performance bottleneck, we need to use async I/O profile with xcode instruments Mar 11, 2024
@xusd320 xusd320 added the question Further information is requested label Mar 11, 2024
@sorrycc sorrycc closed this as completed Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants