Want to learn how to find and fix Android app performance bottlenecks accurately? Learn about utilizing profiling tools to find gridlocks and using recycling, object pooling, caching, and AsyncTask to fix them and maximize performance gain in your Android applications.
Slides from my talk at FrameworksDays Android Saturday technical meetup. More details about this event: http://frameworksdays.com/event/android-it-saturday
Profiling tools and Android Performance patternsicemobile
Profiling is one of the most important steps in the development cycle of any app. Although this is well known, we as developers usually don’t know the potential of every tool that we have to help us. In this presentation we would like to introduce the most useful tools at our disposal that we may use to profile the GPU and memory performance, the most typical problems that our apps might have and how to solve them making use of the android performance patterns.
This presentation aims to demonstrate the importance of certain practices in Android Application Development to avoid annoying memory leaks which lead to fatal crash .
Want to learn how to find and fix Android app performance bottlenecks accurately? Learn about utilizing profiling tools to find gridlocks and using recycling, object pooling, caching, and AsyncTask to fix them and maximize performance gain in your Android applications.
Slides from my talk at FrameworksDays Android Saturday technical meetup. More details about this event: http://frameworksdays.com/event/android-it-saturday
Profiling tools and Android Performance patternsicemobile
Profiling is one of the most important steps in the development cycle of any app. Although this is well known, we as developers usually don’t know the potential of every tool that we have to help us. In this presentation we would like to introduce the most useful tools at our disposal that we may use to profile the GPU and memory performance, the most typical problems that our apps might have and how to solve them making use of the android performance patterns.
This presentation aims to demonstrate the importance of certain practices in Android Application Development to avoid annoying memory leaks which lead to fatal crash .
Slides from Android Builder's Summit 2014 in San Jose, CA
The 4.4 KitKat release includes the results of “Project Svelte”: a set of tweaks to the operating system to make it run more easily on devices with around 512 MiB RAM. This is likely to be especially important for people working with “Embedded Android”, that is, implementing Android on devices that are not smart phones or tablets.
Android devices running on battery need to be optimized for power.
When taking a look at the CPU this optimization starts typically with the race to idle, meaning to go to finish the workload as fast as possible. However typical Android devices are running on a SoC with many other parts like GPU, hardware decoders, sensors, 2G/3G/4G/Wifi modules...
All these parts need to be optimized to reduce the power consumption, but the biggest part of the problem/solution are applications themselves.
Guessing what software is actually causing high power consumption and mitigating it aren't simple tasks. In this session You will explore typical causes of high power consumption, how to debug them and provide possible solutions.
Android provides a number of APIs, OS tricks, and developer tools around power consumption, you will also get to know, learn, and understand them through this talk.
Performance in Android: Tips and Techniques [IndicThreads Mobile Application ...IndicThreads
Session Presented at 1st IndicThreads.com Conference On Mobile Application Development held on 19-20 November 2010 in Pune, India
WEB: http://M10.IndicThreads.com
------------
Speaker: Anand Hariharan
Abstract:
While desktops and laptops have gotten more and more powerful, performance considerations for applications running on the desktop are not critical to the success of the app.
However, mobile devices are quickly becoming a viable computing platform and many devices now can run various applications which were only seen on the desktop previously.
As the developer community ports applications from desktop to the cell phone, performance becomes a very critical factor for success since cellphones are still under-powered as compared to the desktops.
This presentation will talk about best practices w.r.t performance while developing applications for the Android Platform. It will outline tips and techniques for extracting the best performance from android. These tips and techniques are a collation of well known java best practices that apply to Android as well as our learning at TapNTap as we go about building a next generation user interface for an Internet tablet.
Here are some of the topics that will be covered:
Java performance tips that will enhance your android app performance.
Performance Best practices which will apply even for non-android Java programming.
Architecting to avoid the dreaded “ANR (Application not responding)” dialog.
Benchmarking and tracing tools:
Caliper
Traceview
Building custom views : Tips on how to extract the best frame rate before knocking on OpenGLs door.
Precompute for performance.
Layout tricks to get the best load performance.
Differences between mobile and tablets.
Takeaways for the Audience
Best practices for Java development (performance improvement takeaways for any java app).
Tips/tools and techniques on applying these best practices.
Learn best practices tips to create a successful and maintainable Android app in an Agile evolving environment.
The presentation will be formed from small pieces of tips and examples, followed by a real (open sourced) application, which you could then leverage on your own project.
Practices that will be covered (all of them with regards to Android): Team work, Material design, Android studio, Gradle, CI, Creating Boilerplate code, REST architecture, Performance, Automation, Android SDK's, Android's eco-system and more!
Manipulating Android tasks and back stackRan Nachmany
This is the presentation I gave in Google TLV office on Nov 2011. It talks about how Android manages tasks and the tools we have to manipulate and control the default behavior
So, you're a developer, but you have never worked with iOS? In this session, Ardeleanu will provide a head start on how to plan, build, debug and release iOS 7 apps. The talk will cover a wide range of topics, including: the App Store ecosystem; the nature of an app; iOS 7's new UI and how to migrate from iOS 6; interface design; dev tools (Xcode – IDE, Simulator, Instruments – docs, etc); design patterns; debugging and optimisation; App Store and ad-hoc distribution; and what makes an app successfully.
This document primarily covers micro-optimizations that can improve overall app performance when combined, but it's unlikely that these changes will result in dramatic performance effects. Choosing the right algorithms and data structures should always be your priority, but is outside the scope of this document. You should use the tips in this document as general coding practices that you can incorporate into your habits for general code efficiency.
One of the trickiest problems you'll face when micro-optimizing an Android app is that your app is certain to be running on multiple types of hardware. Different versions of the VM running on different processors running at different speeds. It's not even generally the case that you can simply say "device X is a factor F faster/slower than device Y", and scale your results from one device to others. In particular, measurement on the emulator tells you very little about performance on any device.
To ensure your app performs well across a wide variety of devices, ensure your code is efficient at all levels and aggressively optimize your performance.
Androids' memory management differ from the other operating systems. In this PowerPoint presentation we tried to figure out how it works and how it differs from other operating systems.
Slides from Android Builder's Summit 2014 in San Jose, CA
The 4.4 KitKat release includes the results of “Project Svelte”: a set of tweaks to the operating system to make it run more easily on devices with around 512 MiB RAM. This is likely to be especially important for people working with “Embedded Android”, that is, implementing Android on devices that are not smart phones or tablets.
Android devices running on battery need to be optimized for power.
When taking a look at the CPU this optimization starts typically with the race to idle, meaning to go to finish the workload as fast as possible. However typical Android devices are running on a SoC with many other parts like GPU, hardware decoders, sensors, 2G/3G/4G/Wifi modules...
All these parts need to be optimized to reduce the power consumption, but the biggest part of the problem/solution are applications themselves.
Guessing what software is actually causing high power consumption and mitigating it aren't simple tasks. In this session You will explore typical causes of high power consumption, how to debug them and provide possible solutions.
Android provides a number of APIs, OS tricks, and developer tools around power consumption, you will also get to know, learn, and understand them through this talk.
Performance in Android: Tips and Techniques [IndicThreads Mobile Application ...IndicThreads
Session Presented at 1st IndicThreads.com Conference On Mobile Application Development held on 19-20 November 2010 in Pune, India
WEB: http://M10.IndicThreads.com
------------
Speaker: Anand Hariharan
Abstract:
While desktops and laptops have gotten more and more powerful, performance considerations for applications running on the desktop are not critical to the success of the app.
However, mobile devices are quickly becoming a viable computing platform and many devices now can run various applications which were only seen on the desktop previously.
As the developer community ports applications from desktop to the cell phone, performance becomes a very critical factor for success since cellphones are still under-powered as compared to the desktops.
This presentation will talk about best practices w.r.t performance while developing applications for the Android Platform. It will outline tips and techniques for extracting the best performance from android. These tips and techniques are a collation of well known java best practices that apply to Android as well as our learning at TapNTap as we go about building a next generation user interface for an Internet tablet.
Here are some of the topics that will be covered:
Java performance tips that will enhance your android app performance.
Performance Best practices which will apply even for non-android Java programming.
Architecting to avoid the dreaded “ANR (Application not responding)” dialog.
Benchmarking and tracing tools:
Caliper
Traceview
Building custom views : Tips on how to extract the best frame rate before knocking on OpenGLs door.
Precompute for performance.
Layout tricks to get the best load performance.
Differences between mobile and tablets.
Takeaways for the Audience
Best practices for Java development (performance improvement takeaways for any java app).
Tips/tools and techniques on applying these best practices.
Learn best practices tips to create a successful and maintainable Android app in an Agile evolving environment.
The presentation will be formed from small pieces of tips and examples, followed by a real (open sourced) application, which you could then leverage on your own project.
Practices that will be covered (all of them with regards to Android): Team work, Material design, Android studio, Gradle, CI, Creating Boilerplate code, REST architecture, Performance, Automation, Android SDK's, Android's eco-system and more!
Manipulating Android tasks and back stackRan Nachmany
This is the presentation I gave in Google TLV office on Nov 2011. It talks about how Android manages tasks and the tools we have to manipulate and control the default behavior
So, you're a developer, but you have never worked with iOS? In this session, Ardeleanu will provide a head start on how to plan, build, debug and release iOS 7 apps. The talk will cover a wide range of topics, including: the App Store ecosystem; the nature of an app; iOS 7's new UI and how to migrate from iOS 6; interface design; dev tools (Xcode – IDE, Simulator, Instruments – docs, etc); design patterns; debugging and optimisation; App Store and ad-hoc distribution; and what makes an app successfully.
This document primarily covers micro-optimizations that can improve overall app performance when combined, but it's unlikely that these changes will result in dramatic performance effects. Choosing the right algorithms and data structures should always be your priority, but is outside the scope of this document. You should use the tips in this document as general coding practices that you can incorporate into your habits for general code efficiency.
One of the trickiest problems you'll face when micro-optimizing an Android app is that your app is certain to be running on multiple types of hardware. Different versions of the VM running on different processors running at different speeds. It's not even generally the case that you can simply say "device X is a factor F faster/slower than device Y", and scale your results from one device to others. In particular, measurement on the emulator tells you very little about performance on any device.
To ensure your app performs well across a wide variety of devices, ensure your code is efficient at all levels and aggressively optimize your performance.
Androids' memory management differ from the other operating systems. In this PowerPoint presentation we tried to figure out how it works and how it differs from other operating systems.
ACADGILD:: ANDROID LESSON-How to analyze & manage memory on android like ...Padma shree. T
This Blog is all about memory management in Android. It provides information about how you can analyze & reduce memory usage while developing an Android app.
Memory management is a complex field of computer science and there are many techniques being developed to make it more efficient. This guide is designed to introduce you to some of the basic memory management issues that programmers face.
Even though android is powerful mobile operating system platform still there are few pitfalls. One of them is memory optimization to ensure user never run out of space and do you know how to do it.
Enroll for Android Certification in Mumbai at Asterix Solution to develop your career in Android. Make your own android app after android development training in mumbai provides under guidance of expert Trainers. For more details, visit : http://www.asterixsolution.com/android-development-training.html
Techniques for Writing Embedded Code: Memory Management, Types of Memory, Making the Most of Your RAM, Performance and Battery Life, Libraries, Debugging, Business Models: A Short History of Business Models, Space and Time, From Craft to Mass Production, The Long Tail of the Internet, Learning from History, The Business Model Canvas, Who Is the Business Model For? Models, Make Thing, Sell Thing, Subscriptions, Customisation, Be a Key Resource, Provide Infrastructure: Sensor Networks, Take a Percentage, Funding an Internet of Things Startup, Hobby Projects and Open Source, Venture Capital, Government Funding, Crowdfunding, Lean Startups.
Auto-Encoders and PCA, a brief psychological backgroundAmgad Muhammad
A Psychological background on how we think and store memory to explain the motivation behind the Autoencoders and then comparing the performance, in terms of reconstruction error, of the PCA against the Autoencoders.
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf91mobiles
91mobiles recently conducted a Smart TV Buyer Insights Survey in which we asked over 3,000 respondents about the TV they own, aspects they look at on a new TV, and their TV buying preferences.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
The Art of the Pitch: WordPress Relationships and SalesLaura Byrne
Clients don’t know what they don’t know. What web solutions are right for them? How does WordPress come into the picture? How do you make sure you understand scope and timeline? What do you do if sometime changes?
All these questions and more will be explored as we talk about matching clients’ needs with what your agency offers without pulling teeth or pulling your hair out. Practical tips, and strategies for successful relationship building that leads to closing the deal.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Search and Society: Reimagining Information Access for Radical FuturesBhaskar Mitra
The field of Information retrieval (IR) is currently undergoing a transformative shift, at least partly due to the emerging applications of generative AI to information access. In this talk, we will deliberate on the sociotechnical implications of generative AI for information access. We will argue that there is both a critical necessity and an exciting opportunity for the IR community to re-center our research agendas on societal needs while dismantling the artificial separation between the work on fairness, accountability, transparency, and ethics in IR and the rest of IR research. Instead of adopting a reactionary strategy of trying to mitigate potential social harms from emerging technologies, the community should aim to proactively set the research agenda for the kinds of systems we should build inspired by diverse explicitly stated sociotechnical imaginaries. The sociotechnical imaginaries that underpin the design and development of information access technologies needs to be explicitly articulated, and we need to develop theories of change in context of these diverse perspectives. Our guiding future imaginaries must be informed by other academic fields, such as democratic theory and critical theory, and should be co-developed with social science scholars, legal scholars, civil rights and social justice activists, and artists, among others.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
2. 2
Agenda
• How Android Manages Memory
• How your App Should Manage
Memory
• Performance Tips
3. 3
How Android Manages
Memory
• Android uses paging and memory-
mapping (mmapped) to manage
memory.
• Android does not offer swap space for
memory.
• However, there is one exception any
files mmapped in without
modification, such as code, can be
paged out of RAM if the system wants to
use that memory elsewhere
4. 4
Sharing Memory
In order to fit everything it needs in RAM, Android tries to share RAM pages
across processes. It can do so in the following ways:
1. Each app process is forked from an existing process
called Zygote. The Zygote process starts when the
system boots and loads common framework code and
resources . To start a new app process, the system forks
the Zygote process then loads and runs the app's code in
the new process1.
2. Most static data is mmapped into a process.
3. In many places, Android shares the same dynamic RAM
across processes using explicitly allocated shared
memory regions2
1- using copy-on-write semantics
2- gralloc buffers for UI
5. 5
Allocating and Reclaiming App
Memory
Here are some facts about how Android allocates then reclaims memory from
your app:
• The Dalvik heap for each process is
constrained to a single virtual memory
range. This defines the logical heap
size, which can grow as it needs to (but
only up to a limit that the system
defines for each app).
6. 6
Allocating and Reclaiming App
Memory
• The logical size of the heap is not the
same as the amount of physical
memory used by the heap. When
inspecting your app's heap, Android
computes a value called the
Proportional Set Size (PSS), which
accounts for both dirty and clean pages
that are shared with other processes.
• This (PSS) total is what the system
considers to be your physical memory
footprint.
7. 7
Allocating and Reclaiming App
Memory
• The Dalvik heap does not compact the
logical size of the heap, meaning that
Android does not defragment the heap to
close up space. Android can only shrink
the logical heap size when there is
unused space at the end of the heap.
• But this doesn't mean the physical
memory used by the heap can't shrink.
After garbage collection, Dalvik walks
the heap and finds unused pages, then
returns those pages to the kernel
8. 8
Restricting App Memory
• To maintain a functional multi-tasking
environment, Android sets a hard limit
on the heap size for each app. The
exact heap size limit varies between
devices based on how much RAM the
device has available overall.
• If your app has reached the heap
capacity and tries to allocate more
memory, it will receive
an OutOfMemoryError.
• You might want to query the system to determine exactly how much
heap space you have available on the current device—for example, to
determine how much data is safe to keep in a cache. You can query
the system for this figure by calling getMemoryClass(). This returns
an integer indicating the number of megabytes available for your
app's heap.
9. 9
Switching Apps
• Instead of using swap space when the
user switches between apps, Android
keeps processes that are not hosting
a foreground ("user visible") app
component in a least-recently used
(LRU) cache.
• For example, when the user first
launches an app, a process is created
for it, but when the user leaves the
app, that process does not quit. The
system keeps the process cached, so if
the user later returns to the app, the
process is reused for faster app
switching.
10. 10
Switching Apps
• If your app has a cached process and
it retains memory that it currently does
not need, then your app—even while
the user is not using it—is constraining
the system's overall performance.
• So, as the system runs low on
memory, it may kill processes in the
LRU cache beginning with the process
least recently used, but also giving
some consideration toward which
processes are most memory
intensive.
11. 11
Agenda
• How Android Manages Memory
• How your App Should Manage
Memory
• Performance Tips
12. 12
How your App should manage data
• You should consider RAM constraints
throughout all phases of
development, including during app
design (before you begin
development). There are many ways
you can design and write code that lead
to more efficient results, through
aggregation of the same techniques
applied over and over.
• You should apply the following
techniques while designing and
implementing your app to make it more
memory efficient.
13. 13
1. Use services sparingly
• If your app needs a service to perform
work in the background, do not keep it
running unless it's actively performing
a job. Also be careful to never leak your
service by failing to stop it when its
work is done.
• When you start a service, the system prefers to always keep the
process for that service running. This makes the process very
expensive because the RAM used by the service can’t be used by
anything else or paged out. This reduces the number of cached
processes that the system can keep in the LRU cache, making app
switching less efficient
14. 14
1. Use services sparingly
• So how can we avoid this problem?
• The best way to limit the lifespan of
your service is to use
an IntentService, which finishes itself
as soon as it's done handling the
intent that started it.
• Leaving a service running when it’s not needed is one of the
worst memory-management mistakes an Android app can make.
So don’t be greedy by keeping a service for your app running. Not
only will it increase the risk of your app performing poorly due to
RAM constraints, but users will discover such misbehaving apps and
uninstall them.
15. 15
2. Release memory when your user
interface becomes hidden
• When the user navigates to a different
app and your UI is no longer
visible, you should release any
resources that are used by only your
UI. Releasing UI resources at this time
can significantly increase the system's
capacity for cached processes, which
has a direct impact on the quality of the
user experience.
• Give me an example of a UI resource?
16. 16
2. Release memory when your user
interface becomes hidden
• How can we do this?
• To be notified when the user exits your
UI, implement
the onTrimMemory() callback in
your Activity classes. You should use
this method to listen for the
TRIM_MEMORY_UI_HIDDEN
level, which indicates your UI is now
hidden from view and you should free
resources that only your UI uses.
17. 17
2. Release memory when your user
interface becomes hidden
• Note: your app receives the onTrimMemory() callback
with TRIM_MEMORY_UI_HIDDEN only when all the UI components of your
app process become hidden from the user. This is distinct from
the onStop() callback, which is called when an Activity instance becomes
hidden, which occurs even when the user moves to another activity in
your app.
• So although you should implement onStop() to release activity resources
such as a network connection or to unregister broadcast receivers, you
usually should not release your UI resources until you
receive onTrimMemory(TRIM_MEMORY_UI_HIDDEN).
• This ensures that if the user navigates back from another activity in your
app, your UI resources are still available to resume the activity quickly.
18. 18
3. Release memory as memory
becomes tight
• During any stage of your app's lifecycle, the onTrimMemory()callback also
tells you when the overall device memory is getting low. You should
respond by further releasing resources based on the following memory
levels delivered by onTrimMemory():
• TRIM_MEMORY_RUNNING_MODERATE
• Your app is running and not considered killable, but the device is
running low on memory and the system is actively killing processes
in the LRU cache.
• TRIM_MEMORY_RUNNING_LOW
• Your app is running and not considered killable, but the device is
running much lower on memory so you should release unused
resources to improve system performance (which directly impacts your
app's performance).
• TRIM_MEMORY_RUNNING_CRITICAL
• Your app is still running, but the system has already killed most of
the processes in the LRU cache, so you should release all non-
critical resources now. If the system cannot reclaim sufficient amounts
of RAM, it will clear all of the LRU cache and begin killing processes
that the system prefers to keep alive, such as those hosting a running
service.
19. 19
3. Release memory as memory
becomes tight
• The previous events was given when your app is alive, however there are
different set of levels that you can receive when your app is cached.
• TRIM_MEMORY_BACKGROUND
• The system is running low on memory and your process is near the
beginning of the LRU list. Although your app process is not at a high
risk of being killed, the system may already be killing processes in the
LRU cache. You should release resources that are easy to recover
so your process will remain in the list and resume quickly when the user
returns to your app.
• TRIM_MEMORY_MODERATE
• The system is running low on memory and your process is near the
middle of the LRU list. If the system becomes further constrained for
memory, there's a chance your process will be killed.
• TRIM_MEMORY_COMPLETE
• The system is running low on memory and your process is one of the
first to be killed if the system does not recover memory now. You
should release everything that's not critical to resuming your app
state.
20. 20
4. Check how much memory you
should use
• As mentioned earlier, each Android-powered device has a different
amount of RAM available to the system and thus provides a different heap
limit for each app. You can call getMemoryClass()to get an estimate of
your app's available heap in megabytes. If your app tries to allocate more
memory than is available here, it will receive an OutOfMemoryError.
• In very special situations, you can
request a larger heap size by setting
the largeHeap attribute to "true" in the
manifest <application> tag.
• If you do so, you can
call getLargeMemoryClass() to get an
estimate of the large heap size.
21. 21
4. Check how much memory you
should use
• However, the ability to request a large heap is intended only for a small
set of apps that can justify the need to consume more RAM.
• Think of an example?
• Never request a large heap simply because you've run out of
memory and you need a quick fix—you should use it only when you
know exactly where all your memory is being allocated and why it must
be retained. Yet, even when you're confident your app can justify the
large heap, you should avoid requesting it to whatever extent possible.
Using the extra memory will increasingly be to the detriment of the
overall user experience because garbage collection will take longer and
system performance may be slower when task switching or performing
other common operations.
22. 22
5. Avoid wasting memory with
bitmaps
• When you load a bitmap, keep it
in RAM only at the resolution you
need for the current device's
screen, scaling it down if the
original bitmap is a higher
resolution.
23. 23
6. Use optimized data containers
• Take advantage of optimized containers in the Android
framework, such
as SparseArray,SparseBooleanArray, and LongSparseArray.
• These collections are used to map objects, you can compare this to
Hashmap.
• Advantages:
• Avoid using extra entry object for each mapping.
• Avoid autoboxing for keys and sometimes for values.
• Disadvantages:
• Use binary search for lookups, instead of hashing. Slower for
large number of entries , > 1000, compared to Hashmaps.
24. 24
7. Be aware of memory overhead
• Be knowledgeable about the cost and overhead of the language and
libraries you are using, and keep this information in mind when you
design your app, from start to finish.
• Enums often require more than twice as much memory as
static constants. You should strictly avoid using enums on
Android.
• Every class in Java (including anonymous inner classes) uses
about 500 bytes of code.
• Every class instance has 12-16 bytes of RAM overhead.
• Putting a single entry into a HashMap requires the allocation of
an additional entry object that takes 32 bytes
25. 25
8. Be careful with code abstractions
• Often, developers use abstractions simply as a "good programming
practice," because abstractions can improve code flexibility and
maintenance.
• However, abstractions come at a significant cost:
• Generally they require a fair amount more code that needs to be
executed, requiring more time and more RAM for that code to
be mapped into memory.
• So if your abstractions aren't supplying a significant
benefit, you should avoid them.
26. 26
9. Avoid dependency injection
frameworks
• Using a dependency injection framework such
as Guice or RoboGuice may be attractive because they can
simplify the code you write and provide an adaptive environment
that's useful for testing and other configuration changes.
• However, these frameworks tend to perform a lot of process
initialization by scanning your code for annotations, which can
require significant amounts of your code to be mapped into RAM
even though you don't need it
27. 27
10.Be careful about using external
libraries
• External library code is often not written for mobile environments and
can be inefficient when used for work on a mobile client.
• At the very least, when you decide to use an external
library, you should assume you are taking on a significant
porting and maintenance burden to optimize the library for
mobile.
28. 28
11.Use ProGuard to strip out any
unneeded code
• The ProGuard tool shrinks, optimizes, and obfuscates your code by
removing unused code and renaming classes, fields, and methods
with semantically obscure names.
• Using ProGuard can make your code more compact, requiring fewer
RAM pages to be mapped.
29. 29
Agenda
• How Android Manages Memory
• How your App Should Manage
Memory
• Performance Tips
30. 30
Performance Tips
• This part primarily covers micro-optimizations that can improve
overall app performance when combined.
• but it's unlikely that these changes will result in dramatic
performance effects. Choosing the right algorithms and data
structures should always be your priority, but is outside the scope of
this document.
• There are two basic rules for writing efficient code:
• Don't do work that you don't need to do.
• Don't allocate memory if you can avoid it.
31. 31
1. Avoid Creating Unnecessary
Objects
• Object creation is never free.
• As you allocate more objects in your app, you
will force a periodic garbage
collection, creating little "hiccups" in the user
experience.
• Thus, you should avoid creating object
instances you don't need to.
• Any Ideas on how we can do this??
32. 32
1. Avoid Creating Unnecessary
Objects
• If you have a method returning a string, and
you know that its result will always be
appended to a StringBuffer anyway, change
your signature and implementation so that the
function does the append directly, instead of
creating a short-lived temporary object.
• When extracting strings from a set of input
data, try to return a substring of the original
data, instead of creating a copy. You will create
a new String object, but it will share
the char[] with the data.
33. 33
2. Prefer Static Over Virtual
• If you don't need to access an object's
fields, make your method static.
• Invocations will be about 15%-20% faster.
• It's also good practice, because you can tell
from the method signature that calling the
method can't alter the object's state.
34. 34
3. Use Static Final For Constants
• Consider the following declaration at the top of
a class:
• static int intVal = 42;
• static String strVal = "Hello, world!";
• What do you think is happening? And how
beneficial is the alternative if there is any?
35. 35
4. Avoid Internal Getters/Setters
• In native languages like C++ it's common practice to use getters (i =
getCount()) instead of accessing the field directly (i = mCount).
• However, this is a bad idea on Android. Virtual method calls are
expensive, much more so than instance field lookups. It's reasonable to
follow common object-oriented programming practices and have
getters and setters in the public interface, but within a class you
should always access fields directly.
36. 36
5. Use Enhanced For Loop Syntax
public void zero() {
int sum = 0;
for (int i = 0; i < mArray.length; ++i) {
sum += mArray[i].mSplat;
}
}
• What do you think the problem here?
37. 37
5. Use Enhanced For Loop Syntax
public void one() {
int sum = 0;
Foo[] localArray = mArray;
int len = localArray.length;
for (int i = 0; i < len; ++i) {
sum +=
localArray[i].mSplat;
}
}
public void two() {
int sum = 0;
for (Foo a : mArray) {
sum += a.mSplat;
}
}
• What do you think about
these options?
38. 38
5. Use Enhanced For Loop Syntax
• zero() is slowest, because the JIT can't yet optimize away the cost of
getting the array length once for every iteration through the loop.
• one() is faster. It pulls everything out into local variables, avoiding the
lookups. Only the array length offers a performance benefit.
• two() is fastest for devices without a JIT, and indistinguishable
from one() for devices with a JIT. It uses the enhanced for loop syntax
introduced in version 1.5 of the Java programming language.
• So, you should use the enhanced for loop by default, but consider a
hand-written counted loop for performance-
critical ArrayList iteration.
39. 39
6. Avoid Using Floating-Point
• As a rule of thumb, floating-point is about 2x slower than integer on
Android-powered devices.
• In speed terms, there's no difference between float and double on
the more modern hardware. Space-wise, double is 2x larger.
• As with desktop machines, assuming space isn't an issue, you
should prefer double to float.