Giter Site home page Giter Site logo

indulgein / ybtaskscheduler Goto Github PK

View Code? Open in Web Editor NEW
310.0 12.0 46.0 335 KB

iOS 任务调度器,为 CPU 和内存减负(用于性能优化)

License: MIT License

Objective-C 81.94% Objective-C++ 15.99% Ruby 2.06%
optimizing-performance cpu memory

ybtaskscheduler's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ybtaskscheduler's Issues

疑惑: 真的能保证执行顺序吗

仔细看了代码,认为YBTaskScheduler的执行顺序逻辑并不可用。

双线队列固然能保证每个block任务在queue中是有序的(FIFO、LIFO、优先级),但最后执行的时候是在多个串行队列异步执行的。 然而多个异步线程之间的执行顺序其实是不能保证的,单纯的任务保存有序没有特别的价值。

有关任务的执行思考?

static void addRunLoopObserver() { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ taskSchedulers = [NSHashTable weakObjectsHashTable]; CFRunLoopObserverRef observer = CFRunLoopObserverCreate(CFAllocatorGetDefault(), kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, 0xFFFFFF, runLoopObserverCallBack, NULL); CFRunLoopAddObserver(CFRunLoopGetMain(), observer, kCFRunLoopCommonModes); CFRelease(observer); }); }

利用runloop,将我们收敛的任务执行在runloop运行期间。但是注意到,永远是在main runloop 触发这些任务的执行的。假如,我在子线程中添加了任务,但是主线程卡住了。意味着主线程的runloop 不能够及时的触发状态回调而触发任务执行。而受到牵连的在子线程添加的任务不能够及时执行。这种情况子线程的任务执行情况反而依赖于主线程的卡顿情况.
主线程的卡顿,反而影响到了子线程的执行效率
如果主线程极端卡顿的情况下。多线程执行的优势就不存在了~

`Task`优先级问题

- (void)ybts_addTask:(YBTaskBlock)task priority:(YBTaskPriority)priority {
    if (!task) return;
    
    pthread_mutex_lock(&_lock);
    _deque.push_front(task);
    if (self.ybts_maxNumberOfTasks > 0) {
        while (_deque.size() > self.ybts_maxNumberOfTasks) {
            _deque.pop_front();
        }
    }
    pthread_mutex_unlock(&_lock);
}

YBTSQueueYBTSStack这里没有看到根据优先级插入到相应位置的实现呢

一些小疑问

  • (void)ybts_addTask:(YBTaskBlock)task priority:(YBTaskPriority)priority
    _deque.pop_front();
    高优先级的任务把低优先级的任务挤掉了 在cell这种UI任务场景下有用,但是其他场景低优先级的任务也是有执行的必要的啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.