-
Notifications
You must be signed in to change notification settings - Fork 3k
Add persistent_term:put_new #9695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: maint
Are you sure you want to change the base?
Add persistent_term:put_new #9695
Conversation
CT Test Results 3 files 142 suites 50m 17s ⏱️ For more details on these failures, see this check. Results for commit abb29a7. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
|
Instead of adding |
|
I think a You can define a rudimentary TLDR; I think we should add both functions. |
|
@jhogberg, I think this PR is review ready now. Sorry about the delay - I was busy the past 2 weeks... |
11dd76e to
f67b975
Compare
|
Rebased on master to fix merge conflicts. |
|
@jhogberg, Any updates on this? Do you think you can squeeze it in OTP 28? Also, do you think |
As mentioned in the issue, the window for 28 was closed before you opened it. It can be included in 28.1 at the very earliest. The refactor I mentioned is coming along well. It's feature-complete and offers far better add/update/erase performance (so long as literal GC isn't triggered), but read performance on dynamic keys has taken a hit that is proving a bit annoying to get rid of (statically known keys are effectively free however). I'm confident it'll work out however, and am aiming for OTP 29.
I can't see why not, I'll add it to my refactored version. |
When do you think 28.1 will be released? |
8686210 to
f86462e
Compare
Sorry for the late reply -- I missed the notification. 28.1 will be released early this autumn (September-ish). |
|
@jhogberg, I've rebased to master. I'm hoping you can accept patches for OTP 28.1 now? PS: If your refactor is public, could you share a link? I'm curious what are the changes you plan to make. |
28.1 would be
I've paused work on it because more important things came up. The idea was to use concurrent tries to improve update performance for trivial values, sacrificing a bit of read performance but hopefully regaining it through inline caching. Inline caching of static keys resulted in great performance (marginally more expensive than reading a list head...), but I couldn't make dynamic keys fast enough. I left it just before introducing namespacing, replacing the implicit I've pushed what I've got to https://github.com/jhogberg/otp/tree/john/erts/ctrie-experiment, adding |
20f34e6 to
a490d94
Compare
I've rebased to maint and changed the PR base from master to maint as well.
I think namespacing is a great idea - you reduce module, key pairs into a trivial atom. If you're creating a new hashtable/ctrie for each namespace you also get some additional isolation between namespaces in terms of failures and maybe even GC. Regarding static and dynamic keys, do you mean keys known at compile time? Maybe we could cache all trivial keys (i.e. a key that is an atom)? This may not scale well with persistent terms as they are now, but if caching like this for each namespace was configured intentionally on a case by case basis it may work quite well. |
It looks like you dragged some unrelated commits into it.
It doesn't help GC at all, but it does help lookups and update speed as unrelated things won't need to be considered.
Any key known at load-time (regardless of complexity) was cached at load-time in my prototype, and scaled perfectly without namespaces, so it's something we'll want to do regardless. The barrier required to check if the value was stale (and update if so) was effectively free in my tests as long as it wasn't triggered. Dynamic keys are the tricky bit, where namespacing mainly help by splitting up different use cases; the concurrent tries were miles ahead of the old hash table on updates, and only slightly behind on lookups. If your use-case requires quick updates, you might accept the small loss in lookup speed from using concurrent tries, and otherwise you could still use the old method. |
I rebased and forced pushed before updating the PR's base from master to maint. So GitHub dragged commits from maint that weren't on master. I'm going to make a new branch and cherry-pick my commits on to it and update the PR source branch. Edit: All fixed. Forced pushed from this new branch and renamed it to the old branch's name. |
a490d94 to
591e229
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've managed to unify trapping to a put_common_trap. However, I'm still facing some issues.
Edit: @jhogberg, do you have any suggestions?
This commit better consolidates the implementations of the 2 functions into a single common function.
This commit adds a working trapping mechanism.
4ad5558 to
ae264b8
Compare
- Pass Eterm am_(true|false) instead of a bool - Just return the non-value on trapping instead of yeilding
|
@jhogberg , I've managed to push a working trap that passes all the tests within
Running Any idea what gives? |
jhogberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issues are probably related. Which of the arguments is it?
In the CI run it crashed during persistent_term_SUITE:get_all_race/1, suggesting that the problem is not specific to the new-key part of put_common, at least.
|
@jhogberg, I pushed a working solution few days ago. Not sure why the 32-bit and cross-compile builds failed though. Everything else seems to be in order. |
jhogberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, did you find the cause of the crashes? :)
| state_mref = erts_mk_magic_ref(&hp, &MSO(BIF_P), state_bin); | ||
| ctx = ERTS_MAGIC_BIN_DATA(state_bin); | ||
| TRAPPING_COPY_TABLE(TABLE_DEST, OLD_TABLE, NEW_SIZE, REHASH, LOC_NAME, ERASE_TRAP_CODE, BIF_P) | ||
| if (is_internal_magic_ref(BIF_ARG_1) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did something happen with the formatting here?
| #endif | ||
| remaining = trap_data->remaining < max_iter ? | ||
| trap_data->remaining : max_iter; | ||
| trap_data->remaining : max_iter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this and the other unrelated whitespace change further below, it makes git blame less effective.
|
I never did find the cause, except that it was while trapping. The latest implementation does not crash. |
|
About the formatting, I reformatted the functions I was working on with Emacs' |
I believe the problem is that, at least in
Alright, we'll see if it crashes in the nightly runs. :-) |
|
Fixed the formatting. You were right about the semicolon: https://www.gnu.org/software/emacs/manual/html_node/ccmode/Macros-with-_003b.html I suggested that OTP moves towards something like |
|
@jhogberg Any further changes? Is |
|
Not at the moment, maint is still the right branch. It’s been tested briefly without anything fishy showing up, and it’ll get some more testing after 28.3 is released this Friday. 🙂 |
This PR adds the persistent_term:put_new to conditionally add a key-value only if the key is new.
Closes #9681.
/cc @jhogberg.