Repository navigation
Conversation
…ity (uber#501) In h3.api.basic_int, numpy_int, and memview_int, _out_scalar is the identity function, incurring unnecessary Python function call frames and wrapper overhead on every scalar call. When _out_scalar is _in_scalar (integer-returning flavours), bind scalar functions directly to their _cy Cython implementations while preserving original docstrings and signatures. Eliminates ~18% (and up to 50%+ on ARM) latency on scalar calls. Fixes uber#501.
|
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Resolves #501.
In
h3.api.basic_int,numpy_int, andmemview_int,_out_scalaris bound to_in_scalar(def _in_scalar(x): return x), which acts as an identity function. Every scalar-returning binding previously routed through it:This incurs an unnecessary Python function call frame and identity evaluation overhead on every scalar call (~50-60 ns on x86, ~400+ ns on ARM, accounting for 18% to 52% of the public scalar call latency).
Solution
When
_out_scalar is _in_scalar(i.e. in the integer-returning API flavours):_cyimplementations:latlng_to_cellcell_to_parentcell_to_center_childcells_to_directed_edgeget_directed_edge_originget_directed_edge_destinationdirected_edge_to_cellslocal_ij_to_cellcell_to_vertex_cycallables sohelp(), introspection, and Sphinx autodoc remain completely intact.h3.api.basic_str, where_out_scalar is _cy.int_to_str, the original string conversion wrappers remain active and untouched.Benchmark Results (Issue #501 Reproduction)
public 894 ns | _cy 431 ns | wrapper 464 ns (52% overhead)public 761 ns | _cy 813 ns | wrapper 0 ns (0% overhead)Direct Cython C-call dispatch is achieved with zero Python wrapper frame latency.
Verification
182 passed in 2.74s(pytest tests/test_lib).1552/1552 statements, 100.00% coverage).uvx ruff checkreports zero issues.test_basic_int.py,test_numpy_int.py, andtest_memview_int.pyverifying direct_cybinding, docstrings, and signature invariants.