Skip to content
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

Updated Varien_Object::getData() and added getDataByKey() & getDataByPath() #3245

Closed
wants to merge 4 commits into from
Closed

Updated Varien_Object::getData() and added getDataByKey() & getDataByPath() #3245

wants to merge 4 commits into from

Conversation

sreichel
Copy link
Contributor

@sreichel sreichel commented May 11, 2023

Description (*)

https://magento.stackexchange.com/questions/248180/magento-2-good-practice-to-use-avoid-magic-getters

Idea was to add getDataByKey() & getDataByPath(), but then did some xhprof tests for getData().

https://gist.github.com/sreichel/85730194e5e6ad52876700b4b90aafc3

Code comes from M2 ...

ToDo

Replace magic getters (?)

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • Add yourself to contributors list

@github-actions github-actions bot added Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* labels May 11, 2023
Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested.

@sreichel
Copy link
Contributor Author

Any updates here? (Still no time to work on it)

@fballiano
Copy link
Contributor

I wouldn't know where to start testing it, it's for sure ok but the getdata/setdata is such a core thing that a minor mistake will break everything and there are many use cases to test.
is it absolutely safe to merge it in main?
also, I've no idea how to read the performance data here https://gist.github.com/sreichel/85730194e5e6ad52876700b4b90aafc3

@sreichel
Copy link
Contributor Author

sreichel commented Jul 17, 2023

also, I've no idea how to read the performance data

Indeed, its really hard to read. (also removed some lines) :(

I had testscript, that called getData in a nested loop for 200.002 times with different input ...

  • simple Data .... simplestring
  • nested Data ... my/nested/value ... (these calls use getDataByPath)
  • ...

First chart is for getData(). First two lines are the old and the new method including all sub-calls. The two below is the method i did change.

I dont have the script anymore ... but you can see for 200.002 calls, the old method is called 200.009 time. Depending on input it has called itself and/or strpos ... so old Varien_Object::getData is slower.

Second table compared ...

  • magic methods (slowest)
  • call to getData($key)
  • call to getDataByKey($key) (core code should be checked to use this one)

Code comes from M2 ... im pretty sure, its save to merge.

*
* If $index is specified it will assume that attribute data is an array
* and retrieve corresponding member.
* and retrieve corresponding member. If data is the string - it will be explode
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If data is a string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhh, im no native speaker, but "the" seem correct here.

Hhowever ... can you please use github suggestion function? (ctrl-g)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording in that context is not exactly appropriate. It is not an error to turn this PR upside down, it can reformulated. As I can live with some of the OM translations, I can live with this wording.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: lib/Varien Relates to lib/Varien Component: lib/* Relates to lib/* performance Performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants