Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plan on c++ implementation (at least on base functions) #78

Closed
LivInTheLookingGlass opened this issue Jul 22, 2016 · 3 comments
Closed

Comments

@LivInTheLookingGlass
Copy link
Collaborator

I don't know how to do network I/O in C++, but I do know it's possible to construct and interpret these messages, and I know that my callback structure will work.

At the very least, this can be built as a python C extension. Or more accurately, it could be entirely based in C++ and rely on python for I/O (I believe that's possible).

A definite thing to happen is that the python version will include C++ files at this point. So every import will be of the form:

try:
    import cbase as base
except ImportError:
    import base

And setup.py would have a flag for including C extensions. Roughly:

if sys.argv[-1] == "--universal":
    setup_without_extensions() 
else:
    try:
        setup_with_extensions() 
    except:
        setup_without_extensions() 

Most of that is untested, since I'm just now learning how to use C++ this way, but I believe that will work.

@LivInTheLookingGlass
Copy link
Collaborator Author

LivInTheLookingGlass commented Aug 20, 2016

C++ implementation (not yet pushed) now has everything except compression methods. Has flags, protocol, pathfinding_message. This has, however, revealed some optimizations to make. Namely, as follows:

class example(object):
    def __init__(self, val_1, val_2):
        self.val_1 = val_1
        self.val_2 = val_2
        self.__cache = {}

    @property
    def id(self):
        if self.__cache.get('val_1') == self.val_1 and self.__cache.get('val_2') == self.val_2:
            return self.__cache.get('id')
        self.__cache.update({'val_1': self.val_1,
                             'val_2': self.val_2,
                             'id': self.__id_calc()})
        return self.__cache.get('id')

    def __id_calc(self):
        return hashlib.sha384(self.val_1 + self.val_2).hexdigest()

This saves CPU time in return for a mild hit to memory. In the case of a hash, this would likely save memory in the long run, as each hash calculation consumes more memory than the string result.

@LivInTheLookingGlass
Copy link
Collaborator Author

Now implemented and pushed. No compression is yet supported, though zlib is included as a submodule.

@LivInTheLookingGlass
Copy link
Collaborator Author

C++ is now finished (for the base layer). At some point it will get more documentation, as well as compression and networking.

At the moment, it's ~0.1 ms faster than python at constructing messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant