This repository has been archived by the owner on Jun 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic attribute optimizations (JsonApiClient#281)
* Add a unit test to benchmark dynamic attributes This obviously is the wrong place for this, but it lets me run things quickly. It'll come out before the end. * Check has_attribute? before regexes for setters Sample benchmark before: user system total real read: 1.070000 0.000000 1.070000 ( 1.077592) write: 1.130000 0.010000 1.140000 ( 1.142294) Sample benchmark after: user system total real read: 0.580000 0.010000 0.590000 ( 0.593090) write: 1.170000 0.000000 1.170000 ( 1.180000) * Use end_with? instead of regex engine Not sure this matters yet. * Use (& memoize) a DefaultKeyFormatter This avoids repeatedly checking whether the class responds to `#key_formatter`, calling `#key_formatter`, and checking whether its result is nil. Sample before benchmark: user system total real read: 0.580000 0.000000 0.580000 ( 0.576614) write: 1.130000 0.010000 1.140000 ( 1.141003) Sample after benchmark: user system total real read: 0.570000 0.000000 0.570000 ( 0.571892) write: 0.670000 0.010000 0.680000 ( 0.672004) * Auto-define basic attribute getters from method_missing Sample before benchmark: user system total real read: 0.570000 0.000000 0.570000 ( 0.576622) write: 0.670000 0.000000 0.670000 ( 0.672334) Sample after benchmark: user system total real read: 0.020000 0.000000 0.020000 ( 0.013004) write: 0.640000 0.000000 0.640000 ( 0.647726) Because this defines a method for an attribute when the attribute is accessed, I had to change the spec that checked for handling missing methods for attributes, because it was accessing the attribute, and therefore defining the method.
- Loading branch information