Comments (7)
@dinfuehr What do you think? While I think there is a concern regarding predictability, I think it would be a cool way for the runtime to opportunistically cache hashcodes, speeding up every data-structure that uses it, because things are never computed more than once (modulo harmless race conditions).
from dora.
I am not a fan of adding such magic in general: A class can always cache the hash itself and have some behavior that fits for its use case (e.g. recomputing the hash when setting a field).
I am also not sure whether it makes sense to steal bits from the vtable pointer. This requires us to mask out the low 3-bits when loading something from the vtable ptr, this introduces some overhead. Although not sure how much. However we could steal a bit from the header word - the word right after the vtable pointer in an object (used by the GC for the forwarding pointer and marking bit).
from dora.
I agree with you regarding magic in general.
In this case my experience is that people rarely cache hashcodes, because often they are fine with caching it when it's free (in terms of instance size), but don't want to pay the overhead if it added to the instance size. Usually the concern is that the next person might add another field without considering the instance size, turning their "free" hashcode into one with cost attached.
So I'm not sure it is worth it, but I thought that the hashcode magic in the runtime alleviated some of these concerns, by automatically using the wasted bytes to provide a "free" cached hash, without introducing fears that the next user might add an additional field.
In addition to that, there are some hashmap implementations which cache the hashcodes externally. With this feature, this could be elided for classes which already cache it internally. The benefit compared to manually caching the hashcode is that in this case the position of the cached hashcode is guaranteed, so instead of calling the hash
method, it could read the field directly.
However we could steal a bit from the header word - the word right after the vtable pointer in an object (used by the GC for the forwarding pointer and marking bit).
True, this would make more sense.
from dora.
In addition to that, there are some hashmap implementations which cache the hashcodes externally. With this feature, this could be elided for classes which already cache it internally. The benefit compared to manually caching the hashcode is that in this case the position of the cached hashcode is guaranteed, so instead of calling the
hash
method, it could read the field directly.
Not sure this makes much of a difference: A HashMap has to be specialized for each key/value combination anyway, inlining hash() should then give the same result.
I am not opposed to this, but this seems to require a lot of language features to work properly. Let's postpone this discussion to a later date for now.
from dora.
Agreed. Shall I close this issue or do we want to create a few of these issue tags Github offers and start tagging issues with it (e. g. this one with "postponed" or something)?
from dora.
I am fine with whatever you prefer!
from dora.
I just checked https://github.com/dinfuehr/dora/labels and there seem to exist some tags, but nothing like "postponed". Could you create such a tag and tag this issue with it (I can do neither of those things) and close it?
(I would keep open tickets only for those issues we agree that they should/could be done and can be completed in a reasonable time frame, and distinguish between closed ones we have rejected and ones we might reconsider with tags like "postponed", "rejected", etc.)
from dora.
Related Issues (20)
- Unified Condition Expressions HOT 1
- panic: enum value and `is` HOT 3
- Extending the reach of enums HOT 1
- `toStringHex` and `toStringBinary` strip off leading zeros HOT 1
- Consider turning asserts in @test annotated methods into soft asserts
- Allow defining and calling methods without parentheses
- `--emit-ast` doesn't do anything HOT 2
- The JIT implementation of dora is very cool HOT 1
- reinstate class syntax
- replace `fn` keyword with `fun` keyword
- reinstate `=` for function definition
- implement named parameters
- implement string hash caching
- implement definitional enums
- implement modules (singletons and holders of static functions)
- remove unary operators
- remove bitshift operators
- implement unified condition expressions
- replace procedure syntax with functions having return type `Unit` HOT 1
- How lazy compilation is protected in case of multiple threads? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dora.