Document and data size in ios

We want to give the user the ability to clear "document and data". We first try to calculate the size by summing the size of all the files in that directory FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first. But after calculating the size, we see that the size of the "document and data" that the user sees in the storage is larger than the size of our cache in ios 17. But in earlier versions 16, 15, etc. this directory is not taken into account when calculating the size . Which directories are counted in ios 17? And what directories are taken into account in an earlier version of iOS?

Answered by DTS Engineer in 794497022

We want to give the user the ability to clear "document and data". We first try to calculate the size by summing the size of all the files in that directory FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first.

First off, I have two strong recommendations when it comes to calculating/displaying file/directory sizes to the user:

  1. Whenever possible, try to avoid doing so.

  2. If you must show sizes to the users, design you interface such that direct comparisons between the "systems size" and "your size" are difficult/impossible. For example, showing an approximate value ("~500 MB") instead of a specific one ("531.25 MB") or presenting the sizes of specific files without providing a total size.

The issues here are that, in practice:

-Calculating "the size of a directory" is much trickier than it sounds. For example, simply summing all file sizes will double count symbolic links and clone files, both of which are difficult to properly account for.

-File summations don't account for metadata overhead, which means it can undercount total size when the file count it very, very large.

-The entire file system is highly dynamic, causing the actual directory size to fluctuate faster than the monitoring process can adjust.

Basically, it's very difficult to get "the same" number as the system shows and, even if you did "everything" right, it's STILL possible for the values to not match because your app the system ended up "measuring" at different times. Trying to specifically match the systems value ends up highlighting these issues in a way that tends to distract and confuse the user more than it helps. In concrete terms, compare these two cases:

Case 1: System-> 852 MB App -> 854 MB

Case 2: System-> 852 MB App -> ~850 MB

In the first case, the user immediately starts worrying about the "missing" 2 MB, while in the second case they never even knew there was a difference.

But after calculating the size, we see that the size of the "document and data" that the user sees in the storage is larger than the size of our cache in ios 17.

But in earlier versions 16, 15, etc. this directory is not taken into account when calculating the size . Which directories are counted in ios 17? And what directories are taken into account in an earlier version of iOS?

I believe the basic directory set is the same, though there may have been some changes in how App Groups are accounted for. Does your app include any app extensions?

FYI, if you want to take a closer look at exactly what's happening on disk, the "Disk Space Diagnostics" profile can be helpful. That profile will give you a set of text files listing the entire file system hierarchy of the device and basic metadata about the files (size, dates, etc.).

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

We want to give the user the ability to clear "document and data". We first try to calculate the size by summing the size of all the files in that directory FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first.

First off, I have two strong recommendations when it comes to calculating/displaying file/directory sizes to the user:

  1. Whenever possible, try to avoid doing so.

  2. If you must show sizes to the users, design you interface such that direct comparisons between the "systems size" and "your size" are difficult/impossible. For example, showing an approximate value ("~500 MB") instead of a specific one ("531.25 MB") or presenting the sizes of specific files without providing a total size.

The issues here are that, in practice:

-Calculating "the size of a directory" is much trickier than it sounds. For example, simply summing all file sizes will double count symbolic links and clone files, both of which are difficult to properly account for.

-File summations don't account for metadata overhead, which means it can undercount total size when the file count it very, very large.

-The entire file system is highly dynamic, causing the actual directory size to fluctuate faster than the monitoring process can adjust.

Basically, it's very difficult to get "the same" number as the system shows and, even if you did "everything" right, it's STILL possible for the values to not match because your app the system ended up "measuring" at different times. Trying to specifically match the systems value ends up highlighting these issues in a way that tends to distract and confuse the user more than it helps. In concrete terms, compare these two cases:

Case 1: System-> 852 MB App -> 854 MB

Case 2: System-> 852 MB App -> ~850 MB

In the first case, the user immediately starts worrying about the "missing" 2 MB, while in the second case they never even knew there was a difference.

But after calculating the size, we see that the size of the "document and data" that the user sees in the storage is larger than the size of our cache in ios 17.

But in earlier versions 16, 15, etc. this directory is not taken into account when calculating the size . Which directories are counted in ios 17? And what directories are taken into account in an earlier version of iOS?

I believe the basic directory set is the same, though there may have been some changes in how App Groups are accounted for. Does your app include any app extensions?

FYI, if you want to take a closer look at exactly what's happening on disk, the "Disk Space Diagnostics" profile can be helpful. That profile will give you a set of text files listing the entire file system hierarchy of the device and basic metadata about the files (size, dates, etc.).

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Document and data size in ios
 
 
Q