-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Optimize form download with entities #6372
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
72d4cdb
Remove extra work in parseEntityFromRecord
seadowg 2fb5f48
Drop benchmark target for download to 30
seadowg 6a8b95e
Add benchmark for search()
seadowg 4a683f8
Target form load time in search() for entity form download
seadowg 8da9dec
Don't generate UUID for every Entity object
seadowg db2fd33
Adjust benchmark numbers based on current passes on FP3
seadowg 75b0f55
Add failing test for property names with special characters
seadowg 8f21378
Support property names with dots and dashes
seadowg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
collect_app/src/androidTest/java/org/odk/collect/android/benchmark/SearchBenchmarkTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.odk.collect.android.benchmark | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.blankOrNullString | ||
import org.hamcrest.Matchers.not | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.RuleChain | ||
import org.junit.runner.RunWith | ||
import org.odk.collect.android.benchmark.support.Benchmarker | ||
import org.odk.collect.android.benchmark.support.benchmark | ||
import org.odk.collect.android.support.TestDependencies | ||
import org.odk.collect.android.support.pages.MainMenuPage | ||
import org.odk.collect.android.support.rules.CollectTestRule | ||
import org.odk.collect.android.support.rules.TestRuleChain.chain | ||
import org.odk.collect.android.test.BuildConfig.ENTITIES_FILTER_SEARCH_TEST_PROJECT_URL | ||
|
||
/** | ||
* Benchmarks the performance of search() forms. [ENTITIES_FILTER_SEARCH_TEST_PROJECT_URL] should be | ||
* set to a project that contains the "100k Entities Filter search()" form. | ||
* | ||
* Devices that currently pass: | ||
* - Fairphone 3 | ||
* | ||
*/ | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class SearchBenchmarkTest { | ||
|
||
private val rule = CollectTestRule(useDemoProject = false) | ||
|
||
@get:Rule | ||
var chain: RuleChain = chain(TestDependencies(true)).around(rule) | ||
|
||
@Test | ||
fun run() { | ||
assertThat( | ||
"Need to set ENTITIES_FILTER_SEARCH_TEST_PROJECT_URL before running!", | ||
ENTITIES_FILTER_SEARCH_TEST_PROJECT_URL, | ||
not(blankOrNullString()) | ||
) | ||
|
||
val benchmarker = Benchmarker() | ||
|
||
rule.startAtFirstLaunch() | ||
.clickManuallyEnterProjectDetails() | ||
.inputUrl(ENTITIES_FILTER_SEARCH_TEST_PROJECT_URL) | ||
.addProject() | ||
|
||
.clickGetBlankForm() | ||
.clickGetSelected() | ||
.clickOK(MainMenuPage()) | ||
|
||
.clickFillBlankForm() | ||
.benchmark("Loading form first time", 20, benchmarker) { | ||
it.clickOnForm("100k Entities Filter search()") | ||
} | ||
|
||
.pressBackAndDiscardForm() | ||
.clickFillBlankForm() | ||
.benchmark("Loading form second time", 2, benchmarker) { | ||
it.clickOnForm("100k Entities Filter search()") | ||
} | ||
|
||
.answerQuestion("Which value do you want to filter by?", "1024") | ||
.benchmark("Filtering select", 2, benchmarker) { | ||
it.swipeToNextQuestion("Filtered select") | ||
} | ||
|
||
benchmarker.assertResults() | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
collect_app/src/androidTest/java/org/odk/collect/android/benchmark/support/Benchmarker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.odk.collect.android.benchmark.support | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers.lessThan | ||
import org.odk.collect.android.support.pages.Page | ||
import org.odk.collect.shared.TimeInMs | ||
|
||
class Benchmarker { | ||
private val stopwatch = Stopwatch() | ||
private val targets = mutableMapOf<String, Long>() | ||
|
||
fun <T> benchmark(name: String, target: Long, action: () -> T): T { | ||
targets[name] = target | ||
return stopwatch.time(name) { | ||
action() | ||
} | ||
} | ||
|
||
fun assertResults() { | ||
printResults() | ||
|
||
targets.entries.forEach { | ||
val time = stopwatch.getTime(it.key) | ||
assertThat("\"${it.key}\" took ${time}s!", time, lessThan(it.value)) | ||
} | ||
} | ||
|
||
private fun printResults() { | ||
println("Benchmark results:") | ||
targets.keys.forEach { | ||
println("$it: ${stopwatch.getTime(it)}s") | ||
} | ||
} | ||
} | ||
|
||
fun <T : Page<T>, Y : Page<Y>> Y.benchmark( | ||
name: String, | ||
target: Long, | ||
benchmarker: Benchmarker, | ||
action: (Y) -> T | ||
): T { | ||
return benchmarker.benchmark(name, target) { | ||
action(this) | ||
} | ||
} | ||
|
||
private class Stopwatch { | ||
|
||
private val times = mutableMapOf<String, Long>() | ||
|
||
fun <T> time(name: String, action: () -> T): T { | ||
val startTime = System.currentTimeMillis() | ||
val result = action() | ||
val endTime = System.currentTimeMillis() | ||
|
||
times[name] = (endTime - startTime) / TimeInMs.ONE_SECOND | ||
return result | ||
} | ||
|
||
fun getTime(name: String): Long { | ||
return times[name]!! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have a full link to that bug? It will be easier to find,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no public reference sadly! The best I can do is the
@see
for the comment in the Android source.