René's URL Explorer Experiment


Title: Reuse stored hashes when building a set from a set/frozenset/dict by fregataa · Pull Request #8491 · RustPython/RustPython · GitHub

Open Graph Title: Reuse stored hashes when building a set from a set/frozenset/dict by fregataa · Pull Request #8491 · RustPython/RustPython

X Title: Reuse stored hashes when building a set from a set/frozenset/dict by fregataa · Pull Request #8491 · RustPython/RustPython

Description: Closes #8489. Changes dict_inner.rs — each entry point computed the hash on its first line and passed only the hash variable downward, so the split is mechanical: the body moves to a *_known_hash variant and the original becomes a wrapper. No logic is duplicated. insert_known_hash, contains_known_hash, remove_if_known_hash, delete_if_exists_known_hash, delete_or_insert_known_hash keys_with_hashes() — yields (key, hash) from the entries, next to the existing keys()/values()/items() The _known_hash suffix follows CPython's "KnownHash" variants (_PyDict_SetItem_KnownHash, _PyDict_Contains_KnownHash, _PyDict_DelItem_KnownHash), which mark the same split as set_add_key/set_add_entry on the set side. keys_with_hashes() keeps with because it really does return the hashes. function/protocol.rs — ArgIterable::as_object(), a pub(crate) accessor for the object before any __iter__ call. The set operations take ArgIterable, which already held the original PyObjectRef in a private field; reaching it lets them dispatch on the source type without changing a single signature (they are passed around as fn(&PySetInner, ArgIterable, &VirtualMachine) -> ... function pointers, so changing them would have rippled widely). builtins/set.rs PySetInner::cached_hashes() — Some(Vec<(key, hash)>) for a set/frozenset (subclasses included, via the existing extract_set) or an exact dict, None otherwise. Same predicates as CPython. add_known_hash / contains_known_hash merge_set / merge_dict now forward the stored hashes Fast path added to union, intersection, difference, symmetric_difference, difference_update, symmetric_difference_update, intersection_update — the existing generic loop stays as the fallback in each PyFrozenSet's Constructor::Args becomes OptionalArg so py_new receives the source object and can hand its stored hashes over via PySetInner::from_object, instead of flattening to Vec first; slot_new keeps only argument parsing and the empty-singleton check Result after dict.fromkeys(map): 10 after frozenset(d): 10 after set(d): 10 after s.difference(d): 10 after s.symmetric_difference_update(d): 10 Testing test_set — Ran 630 tests ... OK (expected failures=10), no new failures test_dict, test_dictviews, test_dictcomps, test_ordered_dict, test_defaultdict, test_userdict, test_setcomps, test_weakset, test_collections, test_copy — all pass test_types, test_builtin, test_iter, test_pickle, test_marshal, test_descr, test_class, test_functools, test_typing — all pass extra_tests/snippets/: builtin_set.py, builtin_dict.py, builtin_dict_union.py, frozen.py Ad-hoc: empty-frozenset singleton, frozenset(f) is f, distinct ids for empty subclass instances, dict subclasses correctly excluded from the exact-dict path, self-referential ops (s.update(s), s.symmetric_difference_update(s)), results not aliasing their operands, error messages unchanged vs CPython 3.14.6 cargo fmt --check clean, cargo clippy -p rustpython-vm --all-targets no new warnings Review note insert_known_hash depends on a contract the callee cannot verify: pass a hash that isn't key.key_hash(vm) and the entry lands in a bucket no lookup will probe, so the key silently disappears. This is documented on the function, and every call site forwards a hash that came from keys_with_hashes() on a container holding that same key object. Worth a careful look. 🤖 Generated with Claude Code Summary by CodeRabbit New Features Frozensets can now be created directly from an optional iterable. Exact frozenset inputs are preserved where applicable. Empty frozenset creation continues to reuse the shared empty instance. Performance Set operations and updates are more efficient by reusing cached element hashes. Improved hashing efficiency for set, frozenset, and dictionary insertion, lookup, deletion, merging, and membership operations.

Open Graph Description: Closes #8489. Changes dict_inner.rs — each entry point computed the hash on its first line and passed only the hash variable downward, so the split is mechanical: the body moves to a *_known_hash v...

X Description: Closes #8489. Changes dict_inner.rs — each entry point computed the hash on its first line and passed only the hash variable downward, so the split is mechanical: the body moves to a *_known_hash v...

Opengraph URL: https://github.com/RustPython/RustPython/pull/8491

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,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-controllerpull_requests
route-actionfiles
fetch-noncev2:94b2dcf0-3393-d352-97f6-d3a9741e282f
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id8942:EA09B:3717756:4903432:6B020989
html-safe-nonce22d88fe3705baa9f77021c0518d7ecc4d2df1bc25e5a9804d6deeb8197896970
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OTQyOkVBMDlCOjM3MTc3NTY6NDkwMzQzMjo2QjAyMDk4OSIsInZpc2l0b3JfaWQiOiI3ODgyMDA2MTAzNzQyMDg5NjA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac1c39bb1afa5ca44f5e56b3e4bbcdd4f57959c4f829e943c3aeb5d787867aec05
hovercard-subject-tagpull_request:4250797407
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/RustPython/RustPython/pull/8491/files
twitter:imagehttps://avatars.githubusercontent.com/u/44239739?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/44239739?s=400&v=4
og:image:altCloses #8489. Changes dict_inner.rs — each entry point computed the hash on its first line and passed only the hash variable downward, so the split is mechanical: the body moves to a *_known_hash v...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git
octolytics-dimension-user_id39710557
octolytics-dimension-user_loginRustPython
octolytics-dimension-repository_id135201145
octolytics-dimension-repository_nwoRustPython/RustPython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id135201145
octolytics-dimension-repository_network_root_nwoRustPython/RustPython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/RustPython/RustPython/pull/8491/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8491%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FRustPython%2FRustPython%2Fpull%2F8491%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=RustPython%2FRustPython
Reloadhttps://github.com/RustPython/RustPython/pull/8491/files
Reloadhttps://github.com/RustPython/RustPython/pull/8491/files
Reloadhttps://github.com/RustPython/RustPython/pull/8491/files
RustPythonhttps://github.com/RustPython
RustPythonhttps://github.com/RustPython/RustPython
Codehttps://github.com/RustPython/RustPython
Issues195 (195)https://github.com/RustPython/RustPython/issues
Pull requests133 (133)https://github.com/RustPython/RustPython/pulls
Discussionshttps://github.com/RustPython/RustPython/discussions
Actionshttps://github.com/RustPython/RustPython/actions
Projectshttps://github.com/RustPython/RustPython/projects
Wikihttps://github.com/RustPython/RustPython/wiki
Security and qualityhttps://github.com/RustPython/RustPython/security
Insightshttps://github.com/RustPython/RustPython/insights
Sign up for GitHub https://github.com/signup?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FRustPython%2FRustPython%2Fissues%2Fnew%2Fchoose
youknowonehttps://github.com/youknowone
RustPython:mainhttps://github.com/RustPython/RustPython/tree/main
fregataa:reuse-stored-hashes-in-set-opshttps://github.com/fregataa/RustPython/tree/reuse-stored-hashes-in-set-ops
Conversation 4 https://github.com/RustPython/RustPython/pull/8491
Commits 3 https://github.com/RustPython/RustPython/pull/8491/commits
Checks 26 https://github.com/RustPython/RustPython/pull/8491/checks
Files changed https://github.com/RustPython/RustPython/pull/8491/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8491/files
Reuse stored hashes when building a set from a set/frozenset/dict https://github.com/RustPython/RustPython/pull/8491/files#top
Show all changes 3 commits https://github.com/RustPython/RustPython/pull/8491/files
2924f86 Reuse stored hashes when building a set from a set/frozenset/dict fregataa Aug 11, 2026 https://github.com/RustPython/RustPython/pull/8491/commits/2924f86ff184e5b28eb684d1e32237f318f4b537
561d16b Rename the hash-carrying variants to *_known_hash fregataa Aug 11, 2026 https://github.com/RustPython/RustPython/pull/8491/commits/561d16be555a857eda83f7957f9c6cf546cfe8f1
e27697d Narrow visibility of the new helpers and trim their docs fregataa Aug 12, 2026 https://github.com/RustPython/RustPython/pull/8491/commits/e27697d0a8c18a79cb1199d80bb9dd0bffd7062a
Clear filters https://github.com/RustPython/RustPython/pull/8491/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8491/files
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8491/files
set.rs https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
dict_inner.rs https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
protocol.rs https://github.com/RustPython/RustPython/pull/8491/files#diff-f5918110bf58e07c9695e730f765e77189b94ed78bd693678700de3587a34f1e
crates/vm/src/builtins/set.rshttps://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
View file https://github.com/fregataa/RustPython/blob/e27697d0a8c18a79cb1199d80bb9dd0bffd7062a/crates/vm/src/builtins/set.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8491/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
coderabbitaihttps://github.com/apps/coderabbitai
Aug 11, 2026https://github.com/RustPython/RustPython/pull/8491/files#r3762433307
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8491/files
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
https://github.com/RustPython/RustPython/pull/8491/files#diff-ca3250b43726cb4327f8b4f6d413151036abc2f00f7c3197f55432013ca2c07f
crates/vm/src/dict_inner.rshttps://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
View file https://github.com/fregataa/RustPython/blob/e27697d0a8c18a79cb1199d80bb9dd0bffd7062a/crates/vm/src/dict_inner.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8491/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
https://github.com/RustPython/RustPython/pull/8491/files#diff-aa3e0344e8fe84f229558c441057af178d20ee5bb19fda4bc01485a9a62bf99e
crates/vm/src/function/protocol.rshttps://github.com/RustPython/RustPython/pull/8491/files#diff-f5918110bf58e07c9695e730f765e77189b94ed78bd693678700de3587a34f1e
View file https://github.com/fregataa/RustPython/blob/e27697d0a8c18a79cb1199d80bb9dd0bffd7062a/crates/vm/src/function/protocol.rs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/RustPython/RustPython/pull/8491/{{ revealButtonHref }}
https://github.com/RustPython/RustPython/pull/8491/files#diff-f5918110bf58e07c9695e730f765e77189b94ed78bd693678700de3587a34f1e
https://github.com/RustPython/RustPython/pull/8491/files#diff-f5918110bf58e07c9695e730f765e77189b94ed78bd693678700de3587a34f1e
Please reload this pagehttps://github.com/RustPython/RustPython/pull/8491/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.