Repository navigation
Conversation
cmaloney
left a comment
There was a problem hiding this comment.
can you add csv.reader / csv.writer benchmarks here? those are the main thing that gets tested here. Maybe something like csv.reader(f) and csv.reader(f, delimiter=';'). For big CSV files the improvement probably isn't large but I'm okay doing this as long as small / less than 1kb files are faster and large files aren't slower (which I suspect is the case, but best to measure)
|
Added benchmarks of |
|
|
||
| if (dialect != NULL) { | ||
| if (PyUnicode_Check(dialect)) { | ||
| dialect = get_dialect_from_registry(dialect, module_state); |
There was a problem hiding this comment.
This as well as I think the tp_alloc, although that I'm not certain of, can end up calling arbitrary code so need to restructure a bit to ensure the borrowed references aren't invalidated by this. Not sure what is going to be simplest for that, experiment with different options a bit.
There was a problem hiding this comment.
Updated to add strong references before tp_alloc and get_dialect_from_registry. Route early returns through err. Initialize self as NULL to safely Py_CLEAR(self) in err. Add new reference to dialect (ret = Py_NewRef(dialect);) before goto err to safely Py_CLEAR(dialect) in err.
There was a problem hiding this comment.
the tp_alloc can't actually run arbitrary python, was a change in 3.15.
There was a problem hiding this comment.
Oh. Removed tp_alloc from the comment.
get_dialect_from_registry() calls PyDict_GetItemRef() which can still run arbitrary overloaded __eq__ or __hash__ code when comparing keys.
…r run arbitrary code since 3.15. `get_dialect_from_registry()` calls `PyDict_GetItemRef()` which can run arbitrary overloaded `__eq__` or `__hash__` code when comparing keys.
Replace the hand-written
dialect_newwith an Argument Clinic + vectorcall. Move_csv_Dialect___replace___impl()from callingdialect_new()todialect_new_helper()to avoid temporary tuple.Error message for too many arguments is now
TypeError: Dialect() takes at most 9 arguments (N given)instead ofTypeError: function takes at most 9 arguments (N given).Benchmark:
Details