-
Notifications
You must be signed in to change notification settings - Fork 167
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
RecursiveOpenStructs are heavy & slow #251
Comments
Maybe we need an option that tells kubeclient to return JSON instead of ROS? |
BTW since that would require a large code change in our usage code (even if it's mostly cosmetic) we need some benchmarks |
can we test the actual size of the things we're returning from kubeclient with |
|
Sorry for repeating... I've never understood why we need ROS. |
@moolitayer me neither. It's also problematic for those keys that have special symbols (e.g. |
FYI related issue #197 |
See #262, add option for raw and avoids ROS (and JSON parsing altogether) |
[don't have time to measure soon but wanted to braindump... cc @ilackarms @simon3z]
Kubeclient wraps all parsed JSONs with RecursiveOpenStructs. ROS does several expensive things:
https://github.com/aetherknight/recursive-open-struct/blob/v1.0.4/lib/recursive_open_struct.rb#L69-L111
https://github.com/ruby/ruby/blob/v2_4_1/lib/ostruct.rb
on construction: deep dup the hash — can be mitigated by setting
:mutate_input_hash
, safe our case.DeepDup
instance around, one per ROS object afaict.When you access fields as methods (
result.foo.bar
): method_missing call, creating a singleton class for each object, and defining 3 methodsfoo
,foo=
,foo_as_a_hash
(per key)! The methods also keep a closure to reference vars fromnew_ostruct_member
. Then it proceeds to[:foo]
access.new_ostruct_member
! (we don't currently care about the CPU but other kubeclient users might)When you access as hash (
result[:foo][:bar]
): recursively contstructs ROS for the children. It's on-demand and memoized but as you walk the data you'll get a tree of ROSs parallel to the original hashes...on
.to_h
to just get the underlying hash: deep dups it — can maybe be cheaper with:preserve_original_keys
?Anyway,
result.to_h
looks like cheapest access option!I have several ideas to try making upstream ROS & OS faster.
The text was updated successfully, but these errors were encountered: