Skip to content

Commit 62e6348

Browse files
Optimize config.ini updates and efficiency improvements report (#436)
* Optimize config.ini updates by batching shell executions - Reduce up to 5 separate shell executions to 1 for AVD configuration - Improves performance by eliminating redundant process spawns - Add comprehensive efficiency report documenting all identified improvements - All existing tests pass, no functional changes Co-Authored-By: Yang <reactivecircus@gmail.com> * Add compiled JS files and remove standalone efficiency report - Include built lib/emulator-manager.js with batched config optimization - Remove EFFICIENCY_REPORT.md as requested - Efficiency report content will be moved to PR description Co-Authored-By: Yang <reactivecircus@gmail.com> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Yang <reactivecircus@gmail.com>
1 parent 450c4c9 commit 62e6348

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

lib/emulator-manager.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,27 @@ function launchEmulator(systemImageApiLevel, target, arch, profile, cores, ramSi
5050
console.log(`Creating AVD.`);
5151
yield exec.exec(`sh -c \\"echo no | avdmanager create avd --force -n "${avdName}" --abi '${target}/${arch}' --package 'system-images;android-${systemImageApiLevel};${target};${arch}' ${profileOption} ${sdcardPathOrSizeOption}"`);
5252
}
53-
if (cores) {
54-
yield exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
55-
}
56-
if (ramSize) {
57-
yield exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
58-
}
59-
if (heapSize) {
60-
yield exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
61-
}
62-
if (enableHardwareKeyboard) {
63-
yield exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
64-
}
65-
if (diskSize) {
66-
yield exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
53+
if (cores || ramSize || heapSize || enableHardwareKeyboard || diskSize) {
54+
const configEntries = [];
55+
if (cores) {
56+
configEntries.push(`hw.cpu.ncore=${cores}`);
57+
}
58+
if (ramSize) {
59+
configEntries.push(`hw.ramSize=${ramSize}`);
60+
}
61+
if (heapSize) {
62+
configEntries.push(`hw.heapSize=${heapSize}`);
63+
}
64+
if (enableHardwareKeyboard) {
65+
configEntries.push('hw.keyboard=yes');
66+
}
67+
if (diskSize) {
68+
configEntries.push(`disk.dataPartition.size=${diskSize}`);
69+
}
70+
if (configEntries.length > 0) {
71+
const configContent = configEntries.join('\\n') + '\\n';
72+
yield exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`);
73+
}
6774
}
6875
// turn off hardware acceleration on Linux
6976
if (process.platform === 'linux' && disableLinuxHardwareAcceleration) {

src/emulator-manager.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,29 @@ export async function launchEmulator(
3737
);
3838
}
3939

40-
if (cores) {
41-
await exec.exec(`sh -c \\"printf 'hw.cpu.ncore=${cores}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
42-
}
43-
44-
if (ramSize) {
45-
await exec.exec(`sh -c \\"printf 'hw.ramSize=${ramSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
46-
}
40+
if (cores || ramSize || heapSize || enableHardwareKeyboard || diskSize) {
41+
const configEntries: string[] = [];
4742

48-
if (heapSize) {
49-
await exec.exec(`sh -c \\"printf 'hw.heapSize=${heapSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
50-
}
51-
52-
if (enableHardwareKeyboard) {
53-
await exec.exec(`sh -c \\"printf 'hw.keyboard=yes\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
54-
}
43+
if (cores) {
44+
configEntries.push(`hw.cpu.ncore=${cores}`);
45+
}
46+
if (ramSize) {
47+
configEntries.push(`hw.ramSize=${ramSize}`);
48+
}
49+
if (heapSize) {
50+
configEntries.push(`hw.heapSize=${heapSize}`);
51+
}
52+
if (enableHardwareKeyboard) {
53+
configEntries.push('hw.keyboard=yes');
54+
}
55+
if (diskSize) {
56+
configEntries.push(`disk.dataPartition.size=${diskSize}`);
57+
}
5558

56-
if (diskSize) {
57-
await exec.exec(`sh -c \\"printf 'disk.dataPartition.size=${diskSize}\n' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini`);
59+
if (configEntries.length > 0) {
60+
const configContent = configEntries.join('\\n') + '\\n';
61+
await exec.exec(`sh -c \\"printf '${configContent}' >> ${process.env.ANDROID_AVD_HOME}/"${avdName}".avd"/config.ini"`);
62+
}
5863
}
5964

6065
// turn off hardware acceleration on Linux

0 commit comments

Comments
 (0)