Closed Noirdemort closed 10 months ago
Hey @Noirdemort ,
I just came across the same issue, got the sample here:
I am trying to build & run BlockBlock app to pause and see where it hangs during Xcode build invocation. ⏳
I have investigated, and seems like the best candidate for the big consumption of the CPU is the line 85 in file named PluginBase.m
.
[self.regexes enumerateObjectsUsingBlock:^(NSRegularExpression* regex, NSUInteger index, BOOL * _Nonnull stop) {
The following happens:
main
function Monitor
instance is created-[Monitor start]
is called from the same main
function of the Daemon-[Monitor start]
there is the following code:
FileCallbackBlock block = ^(File* file)
{
...
//process file event
[self processEvent:file];
}
};
...
//start monitoring
started = [self.fileMon start:events count:sizeof(events)/sizeof(events[0]) csOption:csNone callback:block];
-[Monitor processEvent:]
// ...that cares about the path/file that was just created
plugin = [self findPlugin:file];
PluginBase
, the same I have mentioned in the beginning-[PluginBase isMatch:]
is sent then, which uses regex
to match against the given "event", where "event' is a file system eventAs can be seen in the sample I have provided in the previous message, ICU library is responsible for such enormous CPU consumption.
Due to the nature of file processing, it is not that easy to optimize the process when there is such big bulk operation with file reads/writes occurs in the system.
That being said, there are a few techniques which might improve the situation not only for Xcode, but for all other applications/file operations as well:
cc Patrick @objective-see
I am creating a PR which tries to fix this, but only Patrick will be able to really test this, I cannot invest much time into the XPC debugging setup at the moment, unfortunately 😢
I have created #69 , which addresses the slowness. It introduces concurrent perform into the essential evaluations of rule lookup and event processing.
It might really speed up the event processing, but also might not even work.
cc @objective-see
👋🏻 Hello,
A small update: the last version, 2.2.0
which was just released, on average consumes 50% less of CPU during compilation of Swift compiler. 🎉
Before | After |
---|---|
Test is not deterministic, but overall performance is much better
Hooray! Moving to BTM events (on macOS 14+) allowed file monitoring/processing to drop drastically.
...other improvements coming soon(ish).
I noticed the amount of threads and CPU usage goes dramatically up while doing xcode builds. It slows the whole system down with it resulting in regressions. Should be able to replicate by running BlockBlock and then running xcode builds or run make for a decently big project in terminal - Terminal commands run super slow especially when doing make builds