Title: Use a set when allocating image part names by cakirmert · Pull Request #1639 · python-openxml/python-docx · GitHub
Open Graph Title: Use a set when allocating image part names by cakirmert · Pull Request #1639 · python-openxml/python-docx
X Title: Use a set when allocating image part names by cakirmert · Pull Request #1639 · python-openxml/python-docx
Description: _next_image_partname() checks candidate numbers against a list of image numbers already in use. Store those numbers in a set so these checks no longer repeatedly scan the list. The search still returns the lowest available number and reuses gaps. Name allocation becomes expected O(n) instead of O(n²) per new image, at the cost of some additional temporary memory. Full-operation timings against e45454602b53e8e572b179ccf1c91093ec9f4ed7, using CPython 3.12.6 on Windows 11 with generated 64×48 thumbnails. Timings include document creation or loading, picture insertion, and saving. Workload Before (ms) After (ms) Speedup Pairs 20 distinct PNGs 19.003 19.015 1.00x 20 250 distinct PNGs 174.814 166.176 1.05x 20 1,000 distinct PNGs 2667.254 2095.356 1.27x 7 2,000 distinct PNGs 13661.021 8684.973 1.57x 7 500 mixed PNG/JPEG images 649.474 582.158 1.12x 7 Same PNG repeated 250 times 91.880 92.626 0.99x 20 Load 1,000 images, add 100, save 736.627 534.916 1.38x 7 Paired-run medians after one warmup pair, alternating execution order with fresh inputs. Every ZIP entry's contents and order, image names, and shape counts matched exactly. Small and repeated-image controls were approximately unchanged. Validation: 1,609 existing unit tests and 650 acceptance scenarios passed; Ruff lint, formatting, and git diff --check passed. Existing tests cover choosing the next number and reusing gaps; no test files changed. AI-assisted investigation, implementation, benchmarking, and drafting with Codex.
Open Graph Description: _next_image_partname() checks candidate numbers against a list of image numbers already in use. Store those numbers in a set so these checks no longer repeatedly scan the list. The search still ret...
X Description: _next_image_partname() checks candidate numbers against a list of image numbers already in use. Store those numbers in a set so these checks no longer repeatedly scan the list. The search still ret...
Opengraph URL: https://github.com/python-openxml/python-docx/pull/1639
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:7b91806d-2765-7ea0-f8dd-7d5bf3e2a041 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9FDC:34D413:47FE1D:606FF9:6AFF6C06 |
| html-safe-nonce | ed73b43041c340429df4af0458f24493271ef9a4f3a438a48ca4c0daf815e827 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RkRDOjM0RDQxMzo0N0ZFMUQ6NjA2RkY5OjZBRkY2QzA2IiwidmlzaXRvcl9pZCI6IjM5OTYxNzY3MjY2Mzg5NDczMzQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3c8fcf3a68fe388b38c7e0ea5d4f1347fe1057c985d2a6eb6180cea3dfe1aa87 |
| hovercard-subject-tag | pull_request:5145365141 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python-openxml/python-docx/pull/1639/files |
| twitter:image | https://avatars.githubusercontent.com/u/66678730?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/66678730?s=400&v=4 |
| og:image:alt | _next_image_partname() checks candidate numbers against a list of image numbers already in use. Store those numbers in a set so these checks no longer repeatedly scan the list. The search still ret... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6d580fc7098c193d7866bf290c4c2b4859a153e87379f44161f35a4495e6b730 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python-openxml/python-docx git https://github.com/python-openxml/python-docx.git |
| octolytics-dimension-user_id | 3403760 |
| octolytics-dimension-user_login | python-openxml |
| octolytics-dimension-repository_id | 13592924 |
| octolytics-dimension-repository_nwo | python-openxml/python-docx |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 13592924 |
| octolytics-dimension-repository_network_root_nwo | python-openxml/python-docx |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ec5dd94a369dad6e9ce618a1705cbe3b618a2863 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width