Download presentation
Presentation is loading. Please wait.
1
Optimize Your Java Code By Tools
NuPoint Technology Inc. Manager of R&D Dept. Lin, Weicheng
2
Agenda Why to Optimize Your Code? Introduction Optimize by OptimizeIt
Conclusions
3
Why to Optimize Your Code?
Why coding? Why do your program need more execution time or developing time than that of others’? Do you agree that Programming is an ART?
4
Introduction How to write a good program? Bad implementation
Suitable language C++, Java, Perl, Scheme, … Good algorithm You need to learn Algorithm, OS, … Good implementation You need not only a good brain but a good tool Bad implementation Allocate too much memory Instantiate too many objects Bad programmatic logic …
5
Introduction (Cont.) There are several tools for optimization use: OptimizeIt, … Functions of Optimization Tools Profiling Code Coverage Checking Thread Debugging Progress Tracking Request Analyzing
6
Optimize by OptimizeIt
The goal of the optimization A quick introduction to the application Application architecture Integrating JBuilder and OptimizeIt Optimizing your first project
7
The Goal of the Optimization
Using JBuilder and OptimizeIt to solve performance problems with an agent A user with 4000 Messages per day Before the performance tuning Several minutes After the performance tuning < 10 seconds Improvement Less execution time Less required memory
8
A Quick Introduction to the Application
Spam filtering It deletes spam from a user's mailbox using a variety of spam-filtering rules Forwarding of desirable messages to a pager A user can control which messages should be forwarded from their inbox to their pager Mail server-independence The Agent works with any server that supports the POP-3 or IMAP standards Platform-independence The Agent can run on any computer platform that supports Java, making it very flexible to install
9
Application Scenario Scenario
Currently, only a user, with 4,000 messages About 1,000 spam messages Running every five minutes In the need of handling more users
10
Application Architecture
11
Basic Algorithm of the Email Agent
Application startup. Initialize logger. Read mail server connection properties. Read properties for sending a summary report to the user. Initialize internal lists from configuration files. Create and populate the Agent. Connect to the mailbox. Remove spam from the current folder. Get the message list from the inbox. Determine the UIDs of these messages. Get a list of messages that have already been examined already. While only looking at new messages: One at a time, review each message to determine whether or not it is spam. If the message matches an ``allow'' file rule, let it pass through. Otherwise, test the From, Reply-To, and Subject fields, as well as message attachments. If a message matches a notification criteria, send a message to my pager. Close the mailbox and store. Send me summary information about what actions were taken. Be care of your for-loop!
12
Basic Configuration Configuring the application allow.from
allow.subject allow.contents reject.from reject.subject reject.contents
13
Integrating JBuilder and OptimizeIt
Installation
14
Integrating JBuilder and OptimizeIt (Cont.)
15
Optimizing Your First Project
16
Finding the Performance Problems
Java Performance Tuning'' by Jack Shirazi Measure the performance of the application, using tools, and/or by instrumenting the code. Identify the location of any bottlenecks. Think of a hypothesis for the cause of the bottleneck. Consider any factors that might refute your hypothesis. Create a test to isolate the factor identified by the hypothesis. Test the hypothesis. Alter the application to reduce the bottleneck. Test that the alteration improves the performance. Repeat from step 1.
17
Finding the Performance Problems (Cont.)
Simplified version of the process Instrument your code and find the major bottlenecks, using the best tools available Fix the bottlenecks that are causing the biggest problems, don't worry about the others. If you can't fix it, avoid it If performance is now acceptable, celebrate. If not, repeat from step 1
18
Finding the Performance Problems (Cont.)
Fix the bottlenecks that are causing the biggest problems and don't worry about the others Simplified analysis example examineContents() - 70% extractContents() - 20% parseAttachment() - 10%
19
The First Run: An Example of How to Use Avoidance Therapy
21
Drill Down Your Programmatic Flow
Using Contents needs a lot of time Put this line in the last It will be run when needed
23
The Second Run Built in JDK
24
The Third Run: Problems with Regular Expressions
aMatcher.find() wastes too much time indexOf is faster Change the order!
25
aMatcher.find() is still slow, we use aMatcher.matches()
9,956 ms
27
9,548 ms
29
Getting Harder Now 9,548 ms
30
Getting Harder Now (Cont.)
9,353 ms
31
Conclusions Reducing the application runtime from over 52 seconds down to about 9.4 seconds You really need a optimization tool, don’t you? Now, do you agree that Programming is an ART?
32
Thanks!
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.