Coder Social home page Coder Social logo

zconform's Introduction

ZConform

A replacement for as? which runs in constant time instead of O(n) when the conformance is not satisfied.

How it works

ZConform does a one-time scan of all conformances when intialized with ZConformHelper.setup(). This populates a cache that can quickly verify if there are no conformances for a type/protocol pair. See the blog post for more details.

When to use it

If you have many as? casts for different type/protocols and have many (thousands) of conformances in your app, the runtime's default conformance check doesn't work well. It will do a linear scan of all conformances each time a new type/protocol combination is checked. If you know not all the casts will be successful ZConform likely speeds up your app since it can avoid the O(n) operation entirely.

Limitations

This implementation is not production ready. It builds the cache as new images are loaded with _dyld_register_func_for_add_image but doesn't have any safeguards if this cache update is performed while a conformance check is ongoing on a different thread. It's also not supporting class bound protocols, and only supports checking conformance of structs. Objective-C bridging also would require a separate implementation, it only works with types defined purely in Swift.

If you‘re interested in productionizing this in your app, please get in touch

zconform's People

Contributors

noahsmartin avatar

Watchers

 avatar

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.