Databinding is quite slow when domain implements traits
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
We have observed that databinding runs quite slower when domain class implements traits.
I have attached the sample which shows the issue. Databinding runs quite slower (some time even 100% slower) on domains which implements traits.
Given a domain class
```
class City {
String name
String shortCode
String state
String country
BigDecimal latitude
BigDecimal longitude
}
@CompileStatic
trait CityTrait {
String name
String shortCode
String state
String country
BigDecimal latitude
BigDecimal longitude
}
class CityWithTrait implements CityTrait {
}
```
Given the City and CityWithTrait domain classes. The databinding the same props on CityWithTrait is quite slower compared to City.
Look at the attached example.
[perftest-bug-report-17112017.zip](https://github.com/grails/grails-core/files/1483026/perftest-bug-report-17112017.zip)
Create a runnable war, or run with bootrun.
The BootStrap runs the databinding on both of the sample domains for a million times and displays the time taken on console. Notice how slow the databinding on domain with trait it.
Bootstrap also manually sets the properties (using assignments) a 1 million time on both domains. Notice there is no big difference on how much time it takes.
So obviously it databinding which is some how getting affected by traits.
### Environment Information
- **Operating System**: OSX
- **Grails Version:** 3.2.11
- **JDK Version:** 1.8
Contributor guide
Research direction
Start with the attached performance example and its Bootstrap, which runs databinding and direct property assignments on both sample domain classes. Run it with bootrun or as a runnable WAR and compare the timings for City and CityWithTrait. Done looks like databinding no longer shows the reported slowdown for the trait-based domain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- backend, performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100