Title: Object representation · Issue #371 · RustPython/RustPython · GitHub
Open Graph Title: Object representation · Issue #371 · RustPython/RustPython
X Title: Object representation · Issue #371 · RustPython/RustPython
Description: Your representation of objects is of particular bad design. Let's examine how much memory we need to store an integer on the stack frame or in a vector. You need to store PyObjectRef, that's Rc
Open Graph Description: Your representation of objects is of particular bad design. Let's examine how much memory we need to store an integer on the stack frame or in a vector. You need to store PyObjectRef, that's Rc X Description: Your representation of objects is of particular bad design. Let's examine how much memory we need to store an integer on the stack frame or in a vector. You need to store PyObjectRef, that'...
Opengraph URL: https://github.com/RustPython/RustPython/issues/371
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Object representation","articleBody":"Your representation of objects is of particular bad design.\r\n\r\nLet's examine how much memory we need to store an integer on the stack frame or in a vector. You need to store `PyObjectRef`, that's `Rc\u003cRefCell\u003cPyObject\u003e\u003e`, that's one pointer (64 bit), one strong reference counter (64 bit), one weak reference counter (64 bit), one borrow counter (64 bit). The strong and weak reference counters and the borrow counter are to be initialized each time a pointer is created.\r\n\r\nThe type `PyObject` consists of `payload: PyObjectPayload` and `typ: Option\u003cPyObjectRef\u003e`. That's again a pointer (64 bit), the `Option::None` is stored as a pointer to NULL, as `PyObjectRef` is non-NULL. The type `PyObjectPayload` is a large enum, 8 up to 64 bit for a tag, and the variant `Integer` stores `BigInt`. `BigInt` consists of `sign: Sign` (8 up to 64 bit) and `data: BigUint` (`Vec\u003cBigDigit\u003e`) (64 bit pointer, 64 bit capacity, 64 bit size). A BigDigit is an `u32`.\r\n\r\nThat's 70 Byte up to 84 Byte for each integer. There are three(!) pointer indirections and eleven(!) memory slots to be initialized. Fragmentation of the allocatator will result in catastrophically bad cache locality. At object destruction, the `PyObjectPayload` enum is branched (hopefully by a branchtable), but as the number of variants is large, it will be a subroutine call (otherwise the branchtable is shadowed by another branch).\r\n\r\nNow consider the following object representation:\r\n```rust\r\ntrait RefTrait {}\r\ntype DynRef = dyn RefTrait;\r\n// You can create your own vtables instead of using dyn,\r\n// given there is an unsolveable issue with dyn.\r\n\r\nenum PyObject {\r\n None,\r\n Bool(bool),\r\n Int(i64),\r\n Float(f64),\r\n Complex(Complex64), // (f64,f64)\r\n Ref(Rc\u003cRefCell\u003cDynRef\u003e\u003e)\r\n}\r\n```\r\nThe tag stores 8 up to 64 bit. The maximal variants are `(f64,f64)` and `(Rc,VTablePointer)`, that's two times 64 bit. This results in 17 Byte up to 24 Byte. Only two memory slots need to be initialized. No memory allocations. Best cache locality.\r\n\r\nAt object destruction, only one branch is needed to determine whether the polymorphic destructor of variant `Ref` is to be called or not. This branch should be inlined.","author":{"url":"https://github.com/JohnBSmith","@type":"Person","name":"JohnBSmith"},"datePublished":"2019-02-06T17:09:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":17},"url":"https://github.com/371/RustPython/issues/371"}
route-pattern /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) route-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:86279a48-24f5-b7fb-f4ed-6fd4dffa37fe current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id B326:D584D:EC7071:13FFB58:6A594A89 html-safe-nonce e62df959278877ff42f95aaebaa6e0ee6b50414b50e8a400012a02e81a06410c visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzI2OkQ1ODREOkVDNzA3MToxM0ZGQjU4OjZBNTk0QTg5IiwidmlzaXRvcl9pZCI6IjE2ODcwMzIzNjkzMjc0NTg5NTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== visitor-hmac 0bc125330a4084bf6872c2cc55d9bfc4703f8ab00324ce7d1500a8642e957e60 hovercard-subject-tag issue:407338780 github-keyboard-shortcuts repository,issues,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/_view_fragments/issues/show/RustPython/RustPython/371/issue_layout twitter:image https://opengraph.githubassets.com/e193fa9d55ca72cd46a7b679567c2c570359923eddd9cb3377db3e27d0a3f09b/RustPython/RustPython/issues/371 twitter:card summary_large_image og:image https://opengraph.githubassets.com/e193fa9d55ca72cd46a7b679567c2c570359923eddd9cb3377db3e27d0a3f09b/RustPython/RustPython/issues/371 og:image:alt Your representation of objects is of particular bad design. Let's examine how much memory we need to store an integer on the stack frame or in a vector. You need to store PyObjectRef, that's Rc og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username JohnBSmith hostname github.com expected-hostname github.com None 9f801e05b35c85b2d72eae6534d2b1d4c02ba8732fd046450bab31e2f52450ce turbo-cache-control no-preview go-import github.com/RustPython/RustPython git https://github.com/RustPython/RustPython.git octolytics-dimension-user_id 39710557 octolytics-dimension-user_login RustPython octolytics-dimension-repository_id 135201145 octolytics-dimension-repository_nwo RustPython/RustPython octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 135201145 octolytics-dimension-repository_network_root_nwo RustPython/RustPython turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release 49918fc503387d6d65b6bc6ce6f711c14d17bfbd ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.