MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.61k stars 627 forks source link

Mailcore blocks the Main Thread #85

Closed pushkarsingh closed 11 years ago

pushkarsingh commented 11 years ago

The main thread get frequently blocked in MCOperationQueue.cc at line #71 mailsem_down(mStopSem)

This is happening when I call following operation multiple time.

- (MCOIMAPFetchContentOperation *) fetchMessageByUIDOperationWithFolder:(NSString *)folder  uid:(uint32_t)uid
void OperationQueue::checkRunningAfterDelay(void * context)
{
    bool quitting = false;

    pthread_mutex_lock(&mLock);
    if (!mQuitting) {
        if (mOperations->count() == 0) {
            MCLog("trying to quit %p", this);
            mailsem_up(mOperationSem);
            mQuitting = true;
            quitting = true;
        }
    }
    pthread_mutex_unlock(&mLock);

    // Number of operations can't be changed because it runs on main thread.
    // And addOperation() should also be called from main thread.

    if (quitting) {
        mailsem_down(mStopSem);
        mStarted = false;
    }

    release(); // (1)
}
CodaFi commented 11 years ago

I'm fairly sure we closed this issue a while ago. Have you pulled all the latest changes in?

dinhvh commented 11 years ago

I think @pushkarsingh is correct. I need to fix it.

dinhvh commented 11 years ago

It's a MailCore 2 issue. I think the main thread gets blocked for a few seconds while the IMAP calls is in finishing.

pushkarsingh commented 11 years ago

@CodaFi I have pulled the latest, the UI stops responding after this happens

screen shot 2013-06-11 at 2 33 38 pm

BTW, I am not sure what is the fastest way of getting few lines of message body to show for the list of emails.

dinhvh commented 11 years ago

Could you show other threads?

to get few lines of a message body, htmlRendering() + flattenHTML is the way to go.

pushkarsingh commented 11 years ago

Here are rest of threads,

screen shot 2013-06-11 at 2 47 28 pm thanks, I was calling htmlRendering, but feel we can improve to have a simple call ti get message body, similar to MailCore1

dinhvh commented 11 years ago

Could you open an other issue to get few lines of an email? Describe how you did in using mailcore and how you do it using mailcore2. I definitively want to improve it.

dinhvh commented 11 years ago

Could you try with the latest changes now? Thanks!

pushkarsingh commented 11 years ago

Looks good !

I understand we have our own implementation of OperationQueue for portability reason. I was wondering if GCD's dispatch queues or NSOperation Queue, would have given a better performance. RIght now all pthreads are created with default priority.

Thanks

dinhvh commented 11 years ago

Since network performance is the main performance hit, we don't need to optimize that yet. Since I want to make sure the implementation will work on all platforms, I want to keep the implementation for now. Until we really encounter a real performance issue.

dinhvh commented 11 years ago

Closing this issue.

pushkarsingh commented 11 years ago

Do you have any suggestions how we can improve the network performance? right now the numbers are on higher side, I have a 20mbps/5mbps connection and

fetchMessagesByUIDOperationWithFolder for a block of 50 mails excluding message body takes ~1 sec, and block of 200 mails takes ~4 secs

dinhvh commented 11 years ago

The server you're talking to probably limits the bandwidth (or has limited performance).

pushkarsingh commented 11 years ago

I am using imap.gmail.com

dinhvh commented 11 years ago

Reverted the fix. It caused a crash when sending emails. See #88.

pushkarsingh commented 11 years ago

Do we have a workaround for now? I am really blocked on this one.

dinhvh commented 11 years ago

I'm going to retry the fix and fix the crash issue introduce when using SMTP. For now, you can cherry pick the change in your working set while waiting for the fix.

pushkarsingh commented 11 years ago

The other problem with that fix was that it used to crash every time I enter wrong credentials, I will upload the stack trace , I need to go back to that commit.

dinhvh commented 11 years ago

Since I could not reproduce the issue with SMTP, I added the fix again.

For the other crash, was it the issue #75?