Skip to content

Commit

Permalink
RUMM-610 Optimize memory usage when doing intensive logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ncreated committed Jul 16, 2020
1 parent ff8b34a commit ddf2620
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/Datadog/Core/Persistence/FilesOrchestrator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ internal class FilesOrchestrator {
throw InternalError(description: "data exceeds the maximum size of \(performance.maxObjectSize) bytes.")
}

try purgeFilesDirectoryIfNeeded()

let lastWritableFileOrNil = reuseLastWritableFileIfPossible(writeSize: writeSize)

if let lastWritableFile = lastWritableFileOrNil { // if last writable file can be reused
lastWritableFileUsesCount += 1
return lastWritableFile
} else {
// NOTE: RUMM-610 As purging files directory is a memory-expensive operation, do it only when we know
// that a new file will be created. With SDK's `PerformancePreset` this gives
// the process enough time to not over-allocate internal `_FileCache` and `_NSFastEnumerationEnumerator`
// objects, resulting with a flat allocations graph in a long term.
try purgeFilesDirectoryIfNeeded()

let newFileName = fileNameFrom(fileCreationDate: dateProvider.currentDate())
let newFile = try directory.createFile(named: newFileName)
lastWritableFileName = newFile.name
Expand Down

0 comments on commit ddf2620

Please sign in to comment.