-
Notifications
You must be signed in to change notification settings - Fork 12
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
10 locale objects return references to internal structures not copies #26
10 locale objects return references to internal structures not copies #26
Conversation
Codecov Report
@@ Coverage Diff @@
## master #26 +/- ##
==========================================
+ Coverage 79.42% 79.83% +0.40%
==========================================
Files 16 17 +1
Lines 695 709 +14
Branches 77 77
==========================================
+ Hits 552 566 +14
Misses 112 112
Partials 31 31
Continue to review full report at Codecov.
|
Before I merge this I'd want to see a benchmark to ensure that this isn't a significant regression in speed for DateTime. While returning the internal refs is somewhat gross, in practice I don't think this is something that causes a lot of problems. I assume most people aren't really using the locale objects directly. |
I setup a basic benchmark running The results don't look very promising: Running on
Running on this branch:
With a shallow clone of the array instead of using
With a drop in performance of about 20% in the shallow clone case, I don't think this is worth pursuing. We could a a comment to the affected code parts and document the behavior somewhere and then close this issue. Whats your opinion on this? |
It's a bit discouraging, but I'd suggest benchmarking DateTime instead. That's what people really care about performance-wise. I would expect the hit to be much smaller. It might even be so small that it's invisible. It might also be worth investigating whether dclone is slower than doing it by hand with something like: return ref($ref) eq 'ARRAY' ? [@{$ref}] : ref($ref) eq 'HASH' ? {%{$ref}} : die 'wtf is this ref?'; |
Actually, no need for runtime |
Allright. I looked into this a little further. I added seperate commits to talk about. One, that adds a deep clone to the return of
In the other commit the method generation in The Benchmark now runs two methods from This not beeing a real world benchmark, how would you like to proceed on Benchmark Results: This branch (
On
|
Yeah, a 50% speed hit is not really acceptable. That said, I agree that adding the |
I agree. Reworked the PR. This now contains the changes to the Concerning #10 I drafted an addition to the pod to indicate that the returned array references have to be handled with care. |
the main purpose of exposing this method is to allow the user to quickly modify an existing locale to his needs and register it via `register_from_data`. Returning a deep clone protects the original locale from being affected by the users changes.
This addresses the issue described in #10
rebased to resolve conflict in |
Merged from the CLI. Thanks! |
This addresses #10
I figured I'll give this a try.
This should solve the described issue. I didn't find any other places where we leak internal structures to the outside without creating a copy.
In line 76: If I am not mistaken it would suffice to check if we have an
ARRAY
ref here and create a shallow clone of the array. I went for thedclone
solution for increased safety/compatibility