שימוש בפרופיל בסיסי
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
פרופילים של בסיס משפרים את מהירות הביצוע של הקוד בכ-30% מההפעלה הראשונה, כי הם מדלגים על שלבי הפרשנות וההידור בזמן אמת (JIT) של נתיבי הקוד הכלולים. כשמצרפים פרופיל בסיסי לאפליקציה או לספרייה, מערכת Android Runtime (ART) יכולה לבצע אופטימיזציה של נתיבי הקוד שכלולים בפרופיל באמצעות קומפילציה מראש (AOT). כך משפרים את הביצועים בכל התקנה חדשה של האפליקציה ובכל עדכון של האפליקציה. האופטימיזציה הזו מבוססת על פרופיל (PGO) ומאפשרת לאפליקציות לבצע אופטימיזציה של ההפעלה, לצמצם את הבעיות שקשורות לאינטראקציות ולשפר את הביצועים הכוללים של זמן הריצה מההפעלה הראשונה של משתמשי הקצה.
שיקולי ביצועים ב-Compose
Compose מופצת כספרייה ולא כחלק מפלטפורמת Android.
הגישה הזו מאפשרת לצוות Compose לעדכן את Compose לעיתים קרובות ולתמוך במגוון רחב של גרסאות Android. עם זאת, הפצה של Compose כספרייה כרוכה בעלות.
קוד הפלטפורמה של Android כבר עובר קומפילציה ומופיע במכשיר.
עם זאת, צריך לטעון ספריות כשמפעילים את האפליקציה, ולפרש אותן בשיטת JIT כשצריך. זה עלול להאט את האפליקציה בהפעלה ובפעם הראשונה שמשתמשים בתכונה של ספרייה.
היתרונות של פרופילים בסיסיים
כדי לשפר את הביצועים, אפשר להגדיר פרופילים בסיסיים. הפרופילים האלה מגדירים מחלקות ושיטות שנדרשות למסלולי משתמש קריטיים, והם מופצים עם קובץ ה-APK או ה-AAB של האפליקציה. במהלך התקנת האפליקציה, ART מהדר את הקוד הקריטי הזה בשיטת AOT, כך שהוא מוכן לשימוש כשהאפליקציה מופעלת.
הגדרה טובה של פרופיל בסיסי היא לא תמיד פשוטה, ולכן Compose מגיע עם הגדרה כזו כברירת מחדל. יכול להיות שלא תצטרכו לעשות כלום כדי ליהנות מההטבה הזו. עם זאת, פרופיל ה-Baseline שמגיע עם Compose מכיל רק אופטימיזציות לקוד בספריית Compose.
השוואה לשוק
כדי לקבל את האופטימיזציה הטובה ביותר, צריך ליצור פרופיל בסיסי לאפליקציה באמצעות Macrobenchmark כדי לכסות את תהליכי המשתמש החשובים. כשמגדירים פרופיל משלכם, צריך לבדוק אותו כדי לוודא שהוא עוזר. דרך טובה לעשות זאת היא לכתוב בדיקות Macrobenchmark לאפליקציה ולבדוק את תוצאות הבדיקה בזמן שכותבים ועורכים את פרופיל הבסיס.
דוגמה לאופן כתיבת בדיקות Macrobenchmark לממשק המשתמש של Compose מופיעה בדוגמה של Macrobenchmark Compose.
מקורות מידע נוספים
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# Use a baseline profile\n\n[Baseline Profiles](/baseline-profiles) improve code execution speed by about 30% from the first\nlaunch by avoiding interpretation and just-in-time (JIT) compilation steps for\nincluded code paths. By shipping a Baseline Profile in an app or library, you\nenable Android Runtime (ART) to optimize included code paths through\nahead-of-time (AOT) compilation, providing performance enhancements for every\nnew app install and every app update. This profile-guided optimization (PGO)\nlets apps optimize startup, reduce interaction jank, and improve overall runtime\nperformance from the first launch for end users.\n\nCompose performance considerations\n----------------------------------\n\nCompose is distributed as a library instead of as part of the Android platform.\nThis approach lets the Compose team update Compose frequently and support a wide\nrange of Android versions. However, distributing Compose as a library imposes a\ncost.\n\nAndroid platform code is already compiled and installed on the device.\nLibraries, however, need to be loaded when the app launches and interpreted JIT\nwhen needed. This can slow the app on startup and when it uses a library feature\nfor the first time.\n\nBenefits of baseline profiles\n-----------------------------\n\nYou can improve performance by defining [Baseline Profiles](/topic/performance/baselineprofiles/overview). These profiles\ndefine classes and methods needed on critical user journeys and are distributed\nwith your app's APK or AAB. During app installation, ART compiles this critical\ncode AOT so that it's ready for use when the app launches.\n\nA good Baseline Profile definition is not always straightforward, and because\nof this, Compose ships with one by default. You might not have to do any work to\nsee this benefit. However, the Baseline Profile that ships with Compose only\ncontains optimizations for the code within the Compose library.\n\n### Macrobenchmark\n\nTo get the best optimization, [create a Baseline Profile](/topic/performance/baselineprofiles/create-baselineprofile)\nfor your app that uses [Macrobenchmark](/studio/profile/macrobenchmark-overview) to cover critical user journeys. When\nyou define your own profile, you must test the profile to verify that it's\nhelping. A good way to do that is to write [Macrobenchmark](/studio/profile/macrobenchmark-overview) tests for your\napp and check the test results as you write and revise your Baseline Profile.\n\nFor an example of how to write Macrobenchmark tests for your Compose UI, see the\n[Macrobenchmark Compose sample](https://github.com/android/performance-samples/tree/main/MacrobenchmarkSample).\n\nAdditional Resources\n--------------------\n\n- **[App performance guide](/topic/performance/overview)**: Discover best practices, libraries, and tools to improve performance on Android.\n- **[Inspect Performance](/topic/performance/inspecting-overview):** Inspect app performance.\n- **[Benchmarking](/topic/performance/benchmarking/benchmarking-overview):** Benchmark app performance.\n- **[App startup](/topic/performance/appstartup/analysis-optimization):** Optimize app startup.\n- **[Baseline profiles](/baseline-profiles):** Understand baseline profiles."]]