This is the main part of my ObjC epub files encryptor code
@autoreleasepool {
for(NSMutableString* epub in self.epubs){
bookKey = [[NSMutableString alloc] initWithString:[self genRandStringLength:16]];
[self performSelectorOnMainThread:@selector(encrypt:) withObject:[NSArray arrayWithObjects:epub,bookKey,nil] waitUntilDone:YES];
}
}
The selector “encrypt” includes these method calls
- create folder for epub extraction
- unzip epub file and put the content files into extraction folder
- create ZipFile for encrypted epub
- read each files within extraction folder, create ZipWriteStream and encrypt the file data
- write each encrypted data stream into ZipFile
- close ZipFile and change zip name extension to .epub
The process is quiet fast when it is just started. But the process getting slower and slower as more file had been written. i’m so sorry for i cannot expose the selector’s definition because of my company secrecy policy. but i’m very sure the problem isn’t come from it. Below is the console log sample. actually those files are just the clone of the same file with different name
- Epub Name : A.epub
- Book Key : 4151FDD721564E40
- Time taken : 0.440156
- Epub Name : B.epub
- Book Key : BC23C09C4625429E
- Time taken : 0.675541
- Epub Name : C.epub
- Book Key : AF872798FAEA4EDE
- Time taken : 0.974213
- Epub Name : D.epub
- Book Key : 250C319928E54D2C
- Time taken : 1.332154
- Epub Name : E.epub
- Book Key : EC4EC65605D246EB
- Time taken : 1.705329
- Epub Name : F.epub
- Book Key : E10588A8CB584ACD
- Time taken : 2.209807
- Epub Name : G.epub
- Book Key : 9B572BF9428E4DFB
- Time taken : 2.797980
- Epub Name : H.epub
- Book Key : BC05B2A629C44A85
- Time taken : 3.389614
- Epub Name : I.epub
- Book Key : 79DB7AAFC8CA4655
- Time taken : 4.936718
- Epub Name : J.epub
- Book Key : B0413DF2356048A7
- Time taken : 5.441939
You should profile your program with the Time Profile tool in Instruments, and see what’s taking the time. Also, an inner autorelease pool for that loop might be helpful if memory growth turns out to be an issue.
(For future reference, “I’m quite sure it’s not X” nearly always ends up meaning “It’s X” 😉 )