Added a SimpleBunch C extension type for speeding the most common operations up #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi David,
care to take a look at this pull request?
The thing is that there are some core operations, the most common ones, that I'd like to speed up. If you compile the package now and run this gist for instance
https://gist.github.com/1961505
you'll notice that for what I consider the most commonly used access patterns, which is
well, the difference is an order of magnitude. bunch.SimpleBunch is about 10-15x faster than bunch.Bunch and some 20-30% slower than the plain dict.
There's a caveat though - the reason I'm calling it a 'simple' Bunch is that only getattr and setattr are implemented and even then, setattr assumes everything should be stored as the SimpleBunch's keys, in other words - I haven't seriously played with the whole getattribute machinery on C API level - might be a field for expansion to explore by future contributors and then it may be possible that bunch.Bunch will become a subclass of bunch.SimpleBunch, but that's future for now.
The whole thing is imported optionally, if the extension isn't available, bunch will define SimpleBunch as an alias to regular Bunch.
You might want to have a look at '_simple_bunch_systems' in setup.py and add some other systems that are likely to have a C compiler handy. This of course assumes a C compiler will be always available on any such a system but I hope this isn't that bad an assumption.
What do you think of it?
Cheers!