Performant Django

Video in TIB AV-Portal: Performant Django

Formal Metadata

Performant Django
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 4.0 International:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Since the days of version 1.0, the Django community has added countless features that address performance pain points; everything from cached template loaders to prefetch related(), the staticfiles app to django-debug-toolbar. But how do you use these tools to make your site fast? In this talk we take a meandering survey through the Django/Python performance landscape.
Arithmetic mean Computer animation Meeting/Interview Electronic mailing list 1 (number)
Scripting language Response time (technology) Different (Kate Ryan album) Personal digital assistant Debugger Electronic mailing list Website Procedural programming Cartesian coordinate system
Web page Server (computing) Computer file Multiplication sign Web browser Mereology Graph coloring Attribute grammar Revision control Inference Medical imaging Fluid statics Mathematics File system Computer-assisted translation Physical system Scripting language Standard deviation Data storage device Sound effect Flow separation Category of being Arithmetic mean Process (computing) Personal digital assistant Web-Designer Website File viewer Fiber bundle
Web page Service (economics) Computer file Multiplication sign 1 (number) Web browser Computer icon Number Web 2.0 Medical imaging Fluid statics Coefficient of determination Goodness of fit Estimator Energy level Software testing Extension (kinesiology) God Social class Domain name Area Standard deviation Data storage device Cartesian coordinate system Limit (category theory) Variable (mathematics) Equivalence relation Connected space Cross-site scripting Data management Arithmetic mean Computer animation Angle Software Website Right angle Pattern language Fiber bundle Resultant
Web page Content delivery network Server (computing) View (database) Multiplication sign Set (mathematics) Sound effect Basis <Mathematik> Client (computing) Cartesian coordinate system Template (C++) Fluid statics Latent heat Word Computer animation Different (Kate Ryan album) Single-precision floating-point format File system Website Software framework Physical system
Point (geometry) Default (computer science) Complex (psychology) Code Multiplication sign Gender View (database) Projective plane Set (mathematics) Database Limit (category theory) Perspective (visual) Symbol table Computer programming Product (business) Template (C++) Front and back ends Cache (computing) Computer animation Single-precision floating-point format Order (biology) Touch typing Mathematical optimization
Module (mathematics) Functional (mathematics) Sequel State of matter View (database) Multiplication sign 1 (number) Price index Cartesian coordinate system Mereology System call Theory Element (mathematics) Computer animation Profil (magazine) Term (mathematics) Normal (geometry) Endliche Modelltheorie Middleware Mathematical optimization Library (computing)
Module (mathematics) Functional (mathematics) Server (computing) Standard deviation Game controller Service (economics) Sequel Multiplication sign View (database) Function (mathematics) Cartesian coordinate system Public key certificate Category of being Latent heat Profil (magazine) Query language Personal digital assistant Core dump Endliche Modelltheorie Plug-in (computing) God
Web page Context awareness Functional (mathematics) Overhead (computing) Sequel Multiplication sign System administrator Control flow Field (computer science) Computer programming Frequency Goodness of fit Object model Single-precision floating-point format Core dump Endliche Modelltheorie Series (mathematics) Proxy server Form (programming) Intelligent Network Key (cryptography) Relational database Block (periodic table) Electronic mailing list Sound effect Incidence algebra Subject indexing Process (computing) Computer animation Angle Query language Personal digital assistant Iteration Object (grammar) Table (information) Row (database)
Classical physics Functional (mathematics) Run time (program lifecycle phase) Sequel Interior (topology) State of matter Multiplication sign Equaliser (mathematics) 1 (number) Set (mathematics) Number Programmer (hardware) Centralizer and normalizer Mathematics Programmschleife Profil (magazine) Mathematical optimization Domain name Boolean algebra Block (periodic table) Data storage device Database Total S.A. Degree (graph theory) Exterior algebra Loop (music) Computer animation Personal digital assistant Blog Computer science Self-organization Right angle Object (grammar) Resultant
Point (geometry) Logical constant Axiom of choice Functional (mathematics) Context awareness Group action Computer file Code Multiplication sign Decimal Source code Parameter (computer programming) Function (mathematics) Number Profil (magazine) String (computer science) Covering space Module (mathematics) Standard deviation Potenz <Mathematik> Sound effect Symbol table Uniform resource locator Free variables and bound variables Right angle Object (grammar) Table (information) Row (database)
Complex (psychology) Functional (mathematics) Code Real number Multiplication sign Virtual machine Parameter (computer programming) Event horizon Information technology consulting Number Template (C++) Expected value Mathematics Single-precision floating-point format Core dump Energy level Software testing Utility software Series (mathematics) Social class Validity (statistics) Database Line (geometry) Instance (computer science) System call Performance appraisal Cache (computing) Type theory Computer animation Angle Query language Right angle Quicksort Reading (process)
Computer animation Lecture/Conference
and the 1st list what was it that or was that course so we alternate title for it
and so if a few disclaimers 1st and so FIL I tried it out in things in the stock but it's by no means comprehensive there's really not you hundred different ways you can add performance you that so I tried to focus on from the main ones from the main areas and and so I'm missing something yeah they against the so it'll get started on so performance and
I think 1st is useful as separated out into 2 different kinds of performance and to Froissart eolith with performance under site on the front and back end and they're very very different and how you deal with them and and the implications thereof and they required like significantly different approaches and so I guess 1st on list side before and
performance on when you people lower performance they talk a lot about like 0 I shaved 50 ms of my you know and pointer my my you or whatever on and really do if you're doing well sigh performance and you really should be starting with fine and performance because on 18 90 per cent of the user response time on a typical application will be on the front and the like and so on it's saving 50 ms interview is not that big a difference once I get on optimizing a dollar script loading procedures is going to make a difference and so Steve Souter's on the His work that Yahoo and Google it as the base case performance fundamentalist these really great books about performance applications for early that I would have recommend but on the so the front end and so from an work so in
the categories of friend performance work on the they can be based generally universally applied so what that meaning that when you make the fix'd improve something it's going affect almost every viewer every every page of your site and they often require systems and tooling changes so it's not something it is a lot of it is like dealing with 0 I need to override collect static to do something I need to compile something and put in a certain place so that it works on social assistance to you off teams and for bigger companies a lot of time jobs you want to get involved with some of the stuff and and the other attribute is very often clear system of that an independent best practices so this is not the case with the back and performance work but a lot of fun in performance but there is a best way to do it there is the known best weighted and so on I guess I wouldn't from the start was and going through a few best practices and then talking about how you would do it and inference performance and so the
first one is catching static assets forever so and why would you wanna do this year I do because the server side up you know you're doing 10 15 20 requests a 2nd on your JavaScript CSS a images are really changing and so you know what the browser to constantly be reading those resources every time refresh the page new you know they got a different page has a same script so the ideal way to do this is to catch this uh 1 asset CSS filed of scopolamine file forever and only change it when I the image itself a CSS adults changes and is called basic concept for features caching is a people colors and so how do you do this and will before is the very difficult and now all of you know since several versions ago Django has the static static files of as a standard part Django all you really have to do is static file storage to be cast across storage or if you have your own storage use cat of McPherson and suddenly if you look at he open up like Firebug a web developer tools and you see where that would happen your images your CSS just you'll notice the renamed like cat that J peg became cat . 1 2 3 that effect and that's from something that basically Django does for you and it changes the name of the file every time that's it changes therefore things attached as long as humanly possible on so 2nd best practice bundle
bundle minify compress static assets so the 1st always means a bundling means you have 11 dogs compiles on page you you take you take that you reduce that a 1 a 2 and minifying means you take all extra whitespace among long variable names anything you can add that all compressing simply means to base could use opinion so this is like this typically this is done and by 1 packet so in rails comes like standard and in in Django and to you disagree acetic acid managers do this on the reason why this is reducing the number of requests is a strict benefit and for making applications that if if you have a look at the Powell applications along like if you've if you fire up the Firebug a new look at the network panel when you look at how the low loading you'll notice there's a sex there's pattern to how the assets are loaded it'll like 8 at a time start away for 1 of those 8 to finish and get another 1 and that's because of browsers basically have a limit per domain and how many simultaneous requests allow it but this is a little bit better and a lot more modern browsers but if you ever have to do with Iater or God forbid I 7 and they have know for for assets for connections to a particular domain at 1 time so you'll notice if you have 14 of files it'll be loading floral stock of won't do anything until 1 of those is finished downloading again another 1 another 1 again so we tried using define reduce the number request as low as possible and and static estimators Amanda's do that and so I wanted to use you use can imagine basically get a user and uh external package to really good ones and Django pipelined actively developed the guy you he takes a lot of low questions is always a adding stuff and from the flask world Web assets which also has a large angle of assets extension to it also great this stuff on that's a bonus points the other other the Beverly pipeline much about levels of support is the in your CSS files if you're referencing images and the images 130 2 K it'll take those images will turn the base 64 it'll embedded right the CSS file so on an army as a black maybe like 7 8 9 years ago that best practice for a on reducing the number of requests for like uh website and I have like 50 little icons was was having a designer creates sprites and then using those rights in doing these like CSS offsets the get the next image and make them at an next and so a data your eyes you don't really need to do that you can you can have 50 images each with a little icon you can reference them in your in your CSS file and on the the rest of the steps that as a natural find that replace it with the base 64 equivalent and you have to deal with the managing sprites on OK
best practice and start serving static files ICT and society on is to provide less less latency user but if any like the bigger shops like you guys do performance wondering and testing and a lot of performance finding tools will show you like the results as if your site was ordered in Brazil and as it was little Russian as if you know result will keep service in those areas and I'll tell you what the latency is that you are really notice it may be locally because you're in New York in your service originally but in Brazil them might getting it clearly different for interrupted and so that's like it pays the the CDN and so using CNNs in GenGO is a fairly simple then is of a bunch of ways to do it and 1 good way we like and user extended college storages which provides custom storage of the classes and we we haven't used S 3 1 we put we Staller acetic acid in 3 we point seed into history and would OK another of best
practice of so serving more stuff acetic acid so this is a kind of a general and I think it's 1 that that is really applicable it so a lot I think I'm pretty like as now using angular using backbone using Amber on you doing less you tumbling in the effect on the server side is lowered going on the client side and so as as low applications turn into like single page applications where the server side is this refers a on and the and the resistive happens on the client side there's an opportunity to store more and more things static assets but as the storm esthetic assets difficult offer servers you can use a CDN so you can catch them forever that all these advantages and so fun and templates like you anger templates pursuing Amber template the perfect candidates for using a set for observing a static assets what that requires a little too independent exactly where JavaScript framework using high stuff is set up but they can never be done we do with angular and it works brilliantly on other thing you can look at is what are the things that are the pieces of data that only change in between releases like us person we have all these like fairly complex menus they're really just like a big pieces of data so we were serving as as you know as part of like a payload and on the server side and it was like getting stuck on the page and the page with loaded on by JavaScript will realize as we could actually just serve those acetic acid have angular grab of static assets and it added it took off several hundred milliseconds from all of our own key endpoints our OK
so let's let's go back and performance work and what you notice that so far and performs word it it's a lot easier to go through because there are some global things you can just do anything that this is the right way to do it you should do it this way back in performance on a lot more nuanced and but often they can be done on a only a case-to-case basis so every site is gonna be different the the user can be different you're approach making gasses in the difference but a lot of time they require coatings as might not to systems and tooling and using a different static file storage and you'd have to get in there understand what that could slow view is doing and and deal with it but like it's it's very site-specific situation specific I so that a global stuff and but there are some global stuff you can do
to do is you can check off realistic newscaster on by default the thing by default Django has a DB sessions on so every every session makes the few the DVD cancer Center either a pure cassation attached DB session and and will take a few of a few it's offered database you use the cash temple of so a couple of 4 5 ago on uh the templates basically every time you make a request symbol we get recompiled they fix that and and the solution was to use a cache temple order and which is basically just agenda setting use it you use in production it works it's a professor of as maybe is slightly controversial but I don't and if it is and so if you're starting a brandy project or existing project that is making like heavyweight usage anger templates you might consider switching the gender too and it's generally considered to be faster and a sentence you know I I would only do new project someone where it's really performance-critical because it is a pain if you actually switching on and you have a fairly big site on but you would you should see some performance benefits of such 2 or starting a project and into 2 instead of using the standard jingo at the templating engine OK so now I
I'm can the real stuff so far so how do you start performance optimizing on the back and I mean 1st it should start with the disclaimer out you don't wanna do this on every view you don't wanna do everywhere you don't wanna like go and they all understand just gonna make my set facet on there is a waste of time you be optimizing stuff that like 5 users a day touch on and unlike unlike for fun and performance where it had some complexity but it's there's like a hard limit how much complexity that come back and performance you can go crazy you can take every view and obfuscated together you know 50 ms up out of it so you really want to pick your spots and pick the key points the performance-sensitive that hundreds of users thousands of users such every single day and work on that because typically performance of optimization on the back end is then add code complexity of 1 program is going to do it in next whatever common understand why this is being done the it's not often obviously doing a lot of the non-obvious things that only makes sense if you're looking at it from a performance perspective so you really wanna pick your battles the but but
let's say you did find problem view of you that was slower than and there was a critical theory application how you start you don't want to start like randomly like of the In sickle Kralik slow undergo optimise it all wiry using the same structurally go fix it if you do that you basically find 1 so what you really wanna do anytime you back informants work you start with a profile of a profile basically tells you and how long is is the taking the return what are the elements of it you know what pieces we should be focusing on and this if you just google the Django Python profile of malaria see like 50 of I there is very good ones I so 1 that we like I'm sure there's some they're just as good if not better on so is a profile look like not
really so still will read everything there but that's what a profile looks like what how it typically works is is the you inside profound middleware and you give a a custom like I did promising and profile people 1 and when the profound where that instead of returning your normal viewing normal days on the terms of the world like that so what you see is typically you'll see the functions recalled how many times called up how how much time each call takes a hammer time call state and this for about 4 were specifically it also gives you modules and how much how much time is spent in bigger model so this gives you a map of OK I have as you the slow what part of that tho is that my function is Django it's equal is it despite and doing is his library died in know about them using where where do I look 1st the so looking at that typically we'll see as you'll see like like but this the sequel problem using 1995 the times spent in Django slash DB slash like my sequel apart and so that give you a good indication OK it's a simple problem and if it's not a simple problem you'll see a lot of like various Python functions at taking up a lot of time however such so the yes things to look for them
so the sense then sequels 1 place you really pretty pretty easily improve the functions that recalled called way too many times see basically every time we've done a profile on like performance that the thing that seems like it's running slower than it should that we've often been and Barisal was ashamed like what we've seen it all my god why there's something ankle 10 thousand times and you know it it should be could be getting call 50 that there must be something wrong and so that the kinds of you look for things you don't expect it's very site-specific you really have to know your application well to know what looks odd tunable both normal and but that's that's constantly looking for you sequel alike all this function is being called to me times taking way longer than I would've expected given what I know it's doing so so
so as it was with the problem of equal you your profile 97 equal solely due and you start with this great tool that there that help you that can diagnose and solve those from generally but a lot of control what everyone here knows what is is is a great tool you install it you you turn on the steeple specific plugin every every find the seal get a sidebar you over the side got the every single query is the how much time the it's sickle cree text i'm SUCH a very helpful to begin with is that where that kind of falls down is if you have on the back and only views based giving the son so then go to the book to well what really attach themselves to that because actually looks for like an HTML to attach to and so in that case is another book of tool called gendered after which the basically replaces the standard Django server and and you can turn on different modules and the different modules 1 of 1 of the model's basically as the view is at has the servicing work it all out for every sequel creates doing and all output and how long each core taking it also it also like mark when the same core is being done 50 candles say like 50 duplicates and so that's on the back and that's really the place to stock certificates legal problems they font into 1 of 2 categories 1 the sequel Corey you're doing is taking too long and to the Eugene too many simple carries and so you know what each of those have different uh ways to
solve and so on the this is basically if you if you look at every you generally assume like every generally favored read the who another way to get around a sequel issues so I think since it is a 1 . also likely it has been around and that each release of the maybe adding different ways to like it is supposed to do what you want to do something to look at a few of them and this is by no means a comprehensive but it'll it'll take 2 of the major thing that we've seen that can can help with sickle and so select related select related and it solves a really common problem Django you have a foreign key you have the I call and and passengers of passengers refer to the car the and and you're going to passengers and you try to like another car they were in and each Korea the passenger will also do according to get the car so you'll see like is reporting 100 kept 100 passengers making 100 queries to get the court say something you might expect excite you know this is you it should be 5 core not you know it's 205 gram and actually if you go the Django admin John Goodman is is really bad at this and if you if you if you ever wrote of objectively but to barter django admin worry reference another model inside the list you'll you'll see 100 queries and if you ever wanna enlarging gladness slow that that uses the reason and so it is all this and like related and slightly basically you you you basically tells angle wired getting the passenger also do a joint internally in pool and get the car so we'll have to get a hundred times the each time where the so values values were so a lot of times and the Python object model that can go returns you and when you do a or temporary is is just the kind of getting in the way of viewed just getting the data where you eventually really do just turn interdict and return this anyway that's that is like a lot of overhead with with creating this single object that is your car is the passenger and it does a lot of stuff to make that happen and you can basically if you know that you know you're not doing anything with the object and economy methods all you really can do is you cannot just take that and put in the Python Dick anyway return it and values values listed 2 ways to do that and they basically turn away so would return date with with the field you wanted the and you can basically a bypass or the Python overhead and DB indexicals true I mean it's like you know a four-year-old see in every sense relational database of existed in this in this is basically an all times so you're you're requiring by particular thing that is not that have an index on and the and the being a lot slower than you'd expect so DB indexes 1 way around that on it
so on another page of sequel tricks you can use and so professional aided and professionally although the critical problem so and select related I mentioned previously it doesn't work in particular doesn't work with many-to-many relationships but it's it's because internally slightly later design with a with a sequel join it doesn't really map well to making that happen in 1 single query and by using joint so what provincial related does it does the basically the same thing it it allows you to like you know let's say in our case a passenger could been in multiple cars so so there's a many-to-many relationship it makes that I work without doing 100 queries and it instead of doing the kind of the matching in and avoiding 100 queries on in sequel what it does is actually does it Django in in in Python really but it it it gets the 2 tables you want it does the matching for you and it allows you to avoid a lot of extra queries and professional and even if the you don't use in many many queries that they it does have certain advantages like we've seen that if you do things like later on for 5 different tables internally in sequel effect of 5 we join which is like a typically typically have really bad big no-no and so sometimes perpetuated on is always faster because is Python-based does a better job than then sequel would the only so only is and so if you if you open up the negative toward you do your typical or and stuff you'll see that every time Jango gets a model or or or or of no series models is actually getting every single field from from sequel and it's not really a problem and until it right so you have you have 5 or 6 feels on a you know a hundred role table and you never really see the problem you have 10 thousand rows and each of those rows have 80 columns and and you happen only need 4 columns in this period is returning the name in the URL it's a and is 76 other columns then it becomes a big problem and so only solve this problem basically what only does is it says but instead of getting all these 80 columns of this table you get before that I know I and all this work with those and it can have as little of a magic so if you happen to know access a field that was in your only and it'll it'll like quarrying get the feel soul fail on as to be a good thing and sensor the use of won't break and why have this uses the abuses cotton it can also be a really bad so if you're using only in getting these 5 you need another program comes along that's all I need the 6 field and make access it without without ever what thing about it so we had situations where suddenly this this this use you know 3 x lower all of what happened 0 something that was like 5 greatest turning to 500 because now each of each and every 1 of those iterations is going and getting the object again because it's missing a field that wasn't the only thing you wanna be sure when you use only that yeah very very careful with it you know use with caution comment it well you know just to be careful at useful but the you know it because of the dangers on the 1st kind of the ins and some of the others only rather thing Hazel field I want you think the the field I don't want similar similar thing at the performance thing you know I know 1 common good thing you do is you know yeah 80 fills and and you don't wanna get too specific about about exactly the fill the wobbly have these 10 big text field that you know you don't want you know you never done need in the context of this year and use the furry those out and you say you say that time it it takes to get their so baulk will create so there's like now ball function BOC updatable create it in and In Django so all you know most of forms from maybe our unary based but you know were a way a financial data company we insert a lot of data we get in big blocks and all created in great for et al basically speeding up the the incidence on so what if all you know you those
until I think there's some other ones too but none of that works and you can always fall back on raw Django basically give you access into hey I need to do query and and just get out of my way so you know ROS Canada last glasses or thing you can do but it can be helpful some sometimes on so the normalisation I mean it's a classic of many new Python Django the classic 1 way to deal with the performance problems as they relate to sequel note a typical case you have a blog the blogger's comments anyone with the number of comments so that can be really slow the attitude that if if the degree every time so instead every time a new comment is written you update this thing called num comments and which keep keeps running can become once the block so it's a very typical of uh old performance trick but it's 1 that's still I think very widely useful of and I just wanna do it out there but it is you know it is something to consider and if you're doing sequel you really doing fickle and oftentimes yes sometimes now and this is the sequels of basically key-value store and and this using the sequel to search on and while in outer dialyzed bodies person you know specific domains are up these days have a lot better by alternate databases readers years sets and lists sorting you know I uh man castra key-value storing and you know whatever the case may be but is something to consider so when sequels that seems to be showing you and
so the other side of performance optimization back in its Python so you know is that you have your profile and sequels 5 or 10 per cent of the total total runtime so size equal if you really but using this Python's of happened and so you know when you look for how you had to deal with it on so you know classic computer science you look for that 1st right you look for some things there you know and squared that don't need to be you you know people you know we know we have had programmers my company you do something you don't even think about it when it's you know there's 10 objects in the in the database you know a year later there's 100 thousand objects in this bad how did you did something shows itself low while that squared that after the problem and so that that organism you look for the you know uh doing extra work in loops that you I see that a lot like people people taking things inside the loop that don't ever change because anything that happens in the world like that's something we i've seen a lot of it you know it the other 1 like you know you have this function it's like you know you don't ever perceived as slow and it does what it does it efficiently it returns you know the result you expecting but it's just loan out that if you ran ran at 10 thousand times inside a loop suddenly the big problem and so really basically made for performance on the Python non-simple side I summon as a of as the people doing death of that moves like almost nothing is a problem until you do it about a 10 of times it's a big problem and so that's what you look for you if you a slow function and then you try to find a place where while like why reading this a why the state you know at the hundreds of a 2nd except we do it a thousand times so fixing the stuff so I wanna give a warning like sometimes just you have to get
weird like sometimes assembling doesn't make sense like what you're doing no sane person would do it until you have this performance problem you solve it and I wanna give 2 examples of of the things that we see in our code and so this is what we saw so
we saw that decimal point 1 and it was used the as a constant function and ends turns out decimal point 1 is like a normal constant right so if the function of the object creation really and you know a least until 3 there 3 3 and he noted the decimal is implanted purely by of kind of slow and so we had a function that had decimal point 1 and it was using it as a ran grounding exponents X something pretty common if you if you guys are familiar with the decimal of module and it was a problem until we had this thing that was different than doesn't rows of data and it was a it was rounding each 1 so it was being run 10 thousand 20 thousand times as only this thing was taking a course effect but this constant like this thing that we're doing nothing right on sources of the solution for us was to make a really really done consonant with cover a file called that 0 . 1 that was evaluated that point 1 and use it and it worked it immediately some mediator profile like all a quarter of 2nd after profile and so this exact problem and I guess would renew pookas and so we do a lot of of and that's what this exact problem is in actually the course and go code if you look at how a decimal thing gets saved 1 things that is the user's constant that's . 1 for the rounding with exact and it was it's just recently showed up in a profile from we tried to save like 10 thousand of doing what create with decimal so something is never think about until you you know you do your profile a goblet with this so example number 2 like and reverse so reverse is great like you know don't repeat yourself just you know reference the URL by name give it give it its argument and the can the the real URL and refers reverses can slow on you know it's fine if you do it once or twice but we had we had a situation where returning that Excel table with with like 5 thousand rows it had this symbol and had the URL you get a symbol it's just an output we needed so we're University doesn't end so group on the on the exact mind you the exact same argue your aligned point not before 1 of the things that's in 1 so I looked exactly like this and ends with end doing it with real there was taking a lot lot longer so instead what we did is we ran it once for the placeholder arguments and then we use string place to replace the place or argument with the real data crazy you would never wanna do it except when you're trying to make something vast and you need to do right and so that's kind to like weird points and I guess who I show points not necessarily to say that you can have the same problems will if you a dozen will probably activist laughing problem but really to show that it's it's it's very very application-specific and sometimes it is going to have to do strange things get things go fast but it it's not obvious and it's not something worth even doing until you know that something is a problem because I don't know sane person would do this context right you would do it as just like standard from day 1 you write this occur because you think is the right thing to do but we do this thing like in very very choice places that we know we have to do it otherwise like this on this I on so whatever but you don't you've done a lot of stuff you're you're you're Python is as fast as it can be done all the weird stuff and the sepals is optimal you can be a long and you're still it's not fast enough and so was the the the classic solutions to performance problems when you've done everything else in the
cash right so caching chasm or anything you catch catch it around so that you know catching is strictly all that is the same as those caching is validation hard on so yeah you can catch anything but obviously users are expecting a status in expectation of how up to date a date is going to be so for you the challenges OK on let me isolate this thing that I wanna cashline was slow let me think about it how often this thing needs to be make no changes or how often it is the up-to-date is something that someone will care about and even if it's you know if the exact number is 6 hours old or is something it's so important that you know it needs to be you know within a minute and date so once you've on isolated these things and then you catch them so how do you test and so you to start reading of being a provides and tools
but those of you catchment which is a Python decorator you can put on have any of you and a lot of Italy and read the arguments real and it'll catch as it as a key based on those arguments and to give you that it can be helpful but there's a template fragment catch so you can do is basically uh just like a temple function you put around any any of piece of note tumbling and basically anything that happens inside that is castle remember the GenGO and core releases of the core you always have will be evaluated until the template is like looping over the thing that at the core returns so it's gonna cast all that stuff and so I can be useful but we've we 1st example or the like more useful levels of caching on don't come necessarily standard can go on for us some of the most useful thing is there's been isolating a function whether be a function of a class of a method in 2nd instance evidence that a class for a class that inside a class and saying hey I wanna catch this on so we have interfaces in the stocks of the stocks have you did a series the Chancellor so really can be thing for us to do is have the stock has a class method or instance method and it returns database on argument and it's very committed place for us to say hey catch this for now and so for that you need a base bifunctional tariff on something that look at that wrap around any function catch on so really popular caching packages coding caching which does functional catching it does a lot of other stuff was in a we we actually wrote 1 call single catch over which only does function type caching and nothing else who we want we don't wanna deal with like other things targeted we just 1 this hundred lines of code that can catch a package so if you if you google Django catch upper and there's very short documentation is use it on and you basically put a decorator and any method instance by the class method whatever and based on the name of that method that's where it is like what models and and the arguments it'll create a key and catch a ral however long your utility on so and then lastly and there's a cookery caching secrete caching is something I think these I noticed that popular in Django maybe 3 years of 3 4 years ago where there's always pack is released on that we're trying to solve the current query catching problems basically how they work is they act they attached and either automatically or whether you implicitly or explicitly you would tell you would you would tell particular and calls to say that to cash for a certain at a time I so to these were 1 was a college angle cash machine and I think in the event of Mozilla and general cash offer thing was just kind of a guy like consultants and and they try assault can 2 different and 1 was just catching queries and the 2nd 1 that they try to solve as automatic evaluation and so knowing and when this scoring should be out of date and then sort and then i'm clearing the catch when they know is going to be out of date and so as a kind of a big topic but I wanted put out there so these things do exist and they are used I think was those please don't look at fishing machine although I could be wrong on a but you the complex and there's a lot a caveat so you know in validation is hard and knowing when to automatically evaluate a query is hard but you can still use these tools to like explicitly invalidate the but implicitly on this becomes caveats but it can be a kind of extremely useful on and I think yeah a few minutes early but that's within my talk it
such my