Skip to content

Commit

Permalink
Merge pull request #185 from DataDog/ncreated/RUMM-610-optimize-memor…
Browse files Browse the repository at this point in the history
…y-usage-when-doing-intensive-logging

RUMM-610 Hotfix memory usage when doing intensive logging
  • Loading branch information
ncreated authored Jul 17, 2020
2 parents b165197 + b887984 commit 969c2d4
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 969c2d4

Please sign in to comment.