Unformatted text preview:

Performance OptimizationHow to make fast softwareFacts of LifeWhy is Smalltalk so fast?Slide 5Wrong way to make fast softwareHow to measure performanceProfiling a ServerSlide 9WikiRendering>>pageSlide 11Process of improving performancePerformance StrategyTechniquesCacheSimplifyReuse objectsInline objects and methodsSmalltalk specificMake Collections of Right SizeUse Streams to ConcatenateAvoid BlocksInlining blocksAvoid ReflectionSchedulingSummaryPerformance OptimizationHow to make fast softwareMake it work.Make it right.Make it fast.Facts of LifeC is 10 times faster than Smalltalk on small benchmarks.Smalltalk business applications are as fast as C business applications.Why is Smalltalk so fast?Smalltalkers can spend more time on optimization.Well-written Smalltalk programs are easy to optimize.Most business programs are limited by network and database, not by CPU.How to make fast softwareMake your software correct and easy to understand.Measure the performance of each part of your program.Find bottlenecks.(80% of the time is spent in 20% of the program)Fix them.Wrong way to make fast softwareChoose most efficient language possible.Make each line of code as efficient as possible.Choose fastest algorithms possible.How to measure performanceProfilers are in the parcel advanced/ATProfiler.pclTimeProfiler profile: [3 + 4]TimeProfiler openViewProfiling a ServerTimeProfiler profile:[100 timesRepeat: [| req |req := WikiClientRequest new.req action: 'GET';... WikiServer current handleRequest: req]].100.0 WikiServer>>handleRequest: 100.0 Wiki>>replyToRequest: 94.6 PageRendering>>renderBody 78.3 PageRendering>>renderCommands 61.7 WikiRendering>>linkTo:titled: 34.2 WikiRendering>>putUrlForCommand: 17.9 WikiRendering>>&= 16.3 WikiRendering>>encodedPageTitle 10.9 WikiRendering>>page 10.9 Wiki>>pageTitled: 5.4 CharacterArray>>asUppercaseWikiRendering>>pagepage^wiki pageTitled: request identifier lastThis method is called several times, so cache it.Add an instance variable called “page”.WikiRendering>>pagepagepage isNil ifTrue: [page := wiki pageTitled: request identifier last].^pageReduced time from .31 seconds to .28 seconds.Process of improving performanceMeasure performance.Make change.Run tests, measure performance.Undo changes if they don’t improve performance.Repeat until performance is good enough.Performance StrategyMake performance targets (e.g.<2 seconds)BenchmarkTry out improvementsOnly install ones that helpStop when you reach your targetsTechniquesBetter algorithmsOptimize low-level designcachesimplifyreuse objectsinline objects and methodsSmalltalk specificCacheStore result in variable and reuse it instead of recomputing it.Move expression out of loop.Store method result in instance variable.You must recompute the result when the values it depends on change.SimplifyInstead of using powerful, easy to use objects, use simple and efficient ones.Arrays instead of OrderedCollectionSymbol instead of StringReuse objectsCreating and collecting objects can take a lot of time.Use AllocationProfiler1) Keep a list of unused objects2) Change object rather than make new oneMake sure object is really unused!Inline objects and methodsLots of small methods can take time.Replace messages in inner loops with thebodies of the methods they call.To eliminate access to an object’s instance variables, eliminate object and put its instance variables in the calling class.This is ugly -- a step of last resort.Smalltalk specificMake collections of right sizesUse streams to concatenateAvoid blocksAvoid reflective programmingMake Collections of Right SizeMany Collections grow: Set, Dictionary, OrderedCollectionGrowing requires copying, which takes time.Make Collections large enough that they don’t have to grow very often.OrderedCollection new: 20Use Streams to Concatenateresult := ‘’.names do: [:each | result := result , each].result := WriteStream on: (String new: 50).names do: [:each | result nextPutAll: each].result contentsAvoid BlocksBlocks are used forpowerful control structuresparameterizing objectsAlternativesin-line the algorithmsmake subclassesInlining blocksCompiler optimizes whileTrue:, to:do:, ifTrue: and does not create a block for them.(1 to: 100) collect: [:each | each * each]result := Array new: 100.1 to: 100 do: [:each | result at: each put: each * each]Avoid Reflectionperform:, doesNotUnderstand: can make programs much smaller and eliminate coding work.They are slower than a normal message send.Scheduling60% - Functionality25% - Refactoring15% - Performance tuningGood performance takes work, so schedule time for it.SummaryPerformance depends more on the programmer than on the programming language.Functionality and good design are harder to achieve than good performance.Don’t let your need for good performance prevent you from making a good


View Full Document

UIUC CS 497 - Performance Optimization

Download Performance Optimization
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Performance Optimization and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Performance Optimization 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?