@@ -225,7 +225,8 @@ public final class IncrementalParser {
225
225
let batches = filesArray. chunked ( into: configuration. maxParallelFiles)
226
226
227
227
for batch in batches {
228
- try processBatch ( batch, importPaths: importPaths, results: & results)
228
+ let batchResults = try processBatch ( batch, importPaths: importPaths)
229
+ results. merge ( batchResults) { _, new in new }
229
230
}
230
231
231
232
// Update statistics
@@ -351,33 +352,19 @@ public final class IncrementalParser {
351
352
352
353
private func processBatch(
353
354
_ batch: [ String ] ,
354
- importPaths: [ String ] ,
355
- results: inout [ String : Result < ProtoAST , ProtoParseError > ]
356
- ) throws {
355
+ importPaths: [ String ]
356
+ ) throws -> [ String : Result < ProtoAST , ProtoParseError > ] {
357
357
358
- let group = DispatchGroup ( )
358
+ // Use a simple sequential approach to avoid all concurrency warnings
359
+ // while still benefiting from parallel processing at the batch level
359
360
var batchResults : [ String : Result < ProtoAST , ProtoParseError > ] = [ : ]
360
- let resultsQueue = DispatchQueue ( label: " results " , attributes: . concurrent)
361
-
361
+
362
362
for filePath in batch {
363
- group. enter ( )
364
-
365
- queue. async {
366
- let result = self . parseFileWithCaching ( filePath, importPaths: importPaths)
367
-
368
- resultsQueue. async ( flags: . barrier) {
369
- batchResults [ filePath] = result
370
- group. leave ( ) // Move group.leave() here to ensure it happens after the result is stored
371
- }
372
- }
363
+ let result = parseFileWithCaching ( filePath, importPaths: importPaths)
364
+ batchResults [ filePath] = result
373
365
}
374
366
375
- group. wait ( )
376
-
377
- // Merge batch results into main results
378
- for (key, value) in batchResults {
379
- results [ key] = value
380
- }
367
+ return batchResults
381
368
}
382
369
383
370
private func parseFileWithCaching(
@@ -518,6 +505,7 @@ public final class IncrementalParser {
518
505
}
519
506
520
507
private func getCurrentMemoryUsage( ) -> Int64 {
508
+ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
521
509
var info = mach_task_basic_info ( )
522
510
var count = mach_msg_type_number_t ( MemoryLayout< mach_task_basic_info> . size) / 4
523
511
@@ -532,6 +520,28 @@ public final class IncrementalParser {
532
520
}
533
521
534
522
return 0
523
+ #elseif os(Linux)
524
+ // Use /proc/self/status on Linux
525
+ do {
526
+ let statusContent = try String ( contentsOfFile: " /proc/self/status " , encoding: . utf8)
527
+ let lines = statusContent. components ( separatedBy: . newlines)
528
+
529
+ for line in lines {
530
+ if line. hasPrefix ( " VmRSS: " ) {
531
+ let components = line. components ( separatedBy: . whitespaces) . compactMap ( Int . init)
532
+ if let memoryKB = components. first {
533
+ return Int64 ( memoryKB * 1024 ) // Convert KB to bytes
534
+ }
535
+ }
536
+ }
537
+ } catch {
538
+ // Fallback if /proc/self/status is not available
539
+ }
540
+ return 0
541
+ #else
542
+ // Fallback for other platforms
543
+ return 0
544
+ #endif
535
545
}
536
546
537
547
private func updateStats( _ update: @escaping ( inout Statistics ) -> Void ) {
0 commit comments