[CDRIVER-1905] SWIG Interface for C Driver Created: 07/Nov/16 Updated: 03/May/17 Resolved: 21/Nov/16 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Joe Drumgoole (Inactive) | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
C Driver |
||
| Description |
|
Would be interesting to see what running the C-Driver through http://www.swig.org/ would produce. |
| Comments |
| Comment by A. Jesse Jiryu Davis [ 21/Nov/16 ] |
|
If anyone desires this, it can be provided outside the C Driver's own repository. |
| Comment by A. Jesse Jiryu Davis [ 08/Nov/16 ] |
|
I would not expect a worthwhile performance gain from a Python wrapper around the C Driver, no matter whether it's SWIG or any other FFI, when compared to PyMongo. Python applications that talk to MongoDB spend most of their time: 1. Waiting for the database or the network As I discovered on a quixotic journey a couple years ago, the time spent in #2 is mostly transcoding strings between BSON's UTF-8 and Python's UCS-2. BSON data always has a lot of strings, and translating between the two encodings takes a while. Python 3.4 optimized the heck out of that path, it's as fast as it will ever be. The rest of the workload for #2 is translating between BSON and Python dicts, lists, ints, etc., and it's implemented in PyMongo in heavily optimized C. Here also, more gains are unlikely. Any Python driver, whether it's PyMongo or something based on the C Driver, has to do this work, and will pay the same cost. The remaining logic that's implemented in Python is #3, and it isn't a large portion of a typical workload. I suspect that the server selection logic is getting slow, but I'm waiting for reproducible benchmark runs in Evergreen before I investigate that. In any case, the stuff in #3 is the only opportunity that a Python API based on the C Driver would have to beat PyMongo, and it's never going to be more than 10 or 20 percent of the cost. Replacing it with the C Driver's implementation probably isn't worth the hassle. If you really want a fast driver, don't translate between Python types and BSON. That's why the C Driver seems fast: it doesn't provide any translation between BSON and HLL data structures. PyMongo has just implemented RawBSONDocument for this purpose, and we're starting to take advantage of it in shane.harvey's BSON-JSON codec and soon, anna.herlihy's and my BSON-NumPy codec. |
| Comment by Joe Drumgoole (Inactive) [ 07/Nov/16 ] |
|
If you like Python, but need C driver speed it would be fairly cool. But not a real thing. @Andrew.Morrow suggested I raise a ticket so I did based on a discussion in the Drivers slack. |
| Comment by A. Jesse Jiryu Davis [ 07/Nov/16 ] |
|
Could you say more about the value of this exercise? =) |