10 ms·
Simple Code, High Performance [video]
- vashishthak 5y agoThat's exactly how i managed to enhance the performance of my site. https://vashishthakapoor.com/ https://vashishthakapoor.com/ Keeping the features along with performance is a big challenge. Video is really explainatory to fix performance issues.
- VHRanger 5y agoWow, your site is indeed fast. Good job!
- vashishthak 5y agoThank you so much mate. Means a lot. :)
- ratww 5y ago+1 here. It's very fast, but it also looks quite good.
- superjan 5y agoSo this guy has had a t-shirt printed with a mirrored logo just to be able to use it with the transparent whiteboard.
- jgwil2 5y agoSo does he have a special reversed image printed on his shirt just for this lecture format?
- isaacimagine 5y agoI looked into this a while back, yep.
- devnull3 5y agoThis was good. I like the presentation. --------- This can be a good interview question for Google to screw people over. I was asked to write a code to generate maze (100x100) with the constraints that it should neither be easy not it should be hard. This was for L6 position.
- omegalulw 5y agoThat's a very interesting. I am curious to hear what your answer was :D Here's my thoughts on what a solution would need: 1. At least one path from source to target. 2. Some quantification of hardness. No of steps in optimal path? Number of turns in optimal path? Number of paths? Some weighted combination of all three? Some preliminaries: Finding optimal path, and finding number of paths can both be down in O(N^2) using DP. Finding number of turns is then trivial. Now the Algos for 1: Algo for 1: Naive backtracking, i.e., randomly generate paths until there are no paths. Evaluate each maze using the heuristic and output best one. Run for some fixed time t. This is exp time. Another algo for 1. Generate a path as following: select K points on the grid, with the start and end being the first and last; then finding optimal paths in sequence (notice that this guarantees not cyclical path). Next, generate fresh path on an empty grid and overlay on the previous path. Keep repeating for some M paths. Now fill in non path pixels. Pick the best grid among these M steps. This is O(M*N^2). Last Algo for 1: Throw the grid into an ILP solver and optimize the heuristic (exp time).
- devnull3 5y agoWell, I addressed the "neither easy nor hard part" upfront. My take was there has to be a solution and that too 1 solution. In other words, it had to be fair. Second was the degree of false paths (term I made-up). This essentially governs the branching of each false path. Higher the degree higher the branching and higher the backtracking. This would make the maze harder. So my algo was 1. To generate a valid path from top-left to bottom-right. (this is simple bfs/dfs walk). This is illustrated as path 1-2-3-4-5-6-7..-10 below. This ensures we have a fair maze. 2. Now from each number below, generate path in an outward manner till it hits walls. These are false paths. The "degree" mentioned above will dictate if there are further branching out of these paths. 1 * * * * * 2 3 * * * * * 4 5 6 * * * * * 7 * * * * * 8 9 10 In the step #1 we note the row,col in a dict/hashmap. We use these in step #2 to ensure the dfs walk dont step on these row,col. This is all I could conjure-up in 45 min including a code in python. I was labelled lean-no hire. Edit: fixed the rendering of the maze
- anandoza 5y ago3 hour video with no timestamps, a minimal description, and comments turned off?
- aetherspawn 5y ago"Simple code" -> very difficult to decipher use of SIMD intrinsics. Yikes. He may have deleted 1000 lines of code, but he'll need a 2 hour inline video (with a 1000 line transcript) to explain how it works.
- dralley 5y agoEven if he had stopped before hand-rolling the SIMD, it'd still be a multiple order of magnitude improvement. I do think it would have been useful to demonstrate that before going straight to hard mode.
- werner1886 5y agoHe measures code 'simplicity' by how much work it makes CPU do, and not some made up metric like 'readability'.
- philosopher1234 5y agoHow exactly is readability made up?
- werner1886 5y agoWe might be thinking about different things here, so let me first ask this: What do you want to measure?
- RedShift1 5y agoSimple example: I love the ternary operator and use it quite a lot in simple "if/then" scenarios. However some people hate them because they consider them harder to read than the fully written out if/then form. Those people would judge my code less readable.
- dsego 5y agoTernary operators are better for expressions, which yield a result, since you don't have to declare or initialize a variable with a dummy value first. If/else is better for general branching. Using ternary without assigning or passing the expression would imho be misleading. I've seen ternaries used for branching and it's a smell imho, they're not really meant for that use case.
- archagon 5y agoI really like this lecture format. What is he drawing on?
- generichuman 5y agoHe uses a lightboard [0] and flips the video. [0] https://www.lightboard.info/ https://www.lightboard.info/
- gary_0 5y agoI guess he filmed through a pane of glass, and then flipped the video? It's trippy that he's physically writing backwards, but the text we see isn't reversed.
- archagon 5y agoWe see the whiteboard text scrolling sometimes, though.
- throwuxiytayq 5y agoI'd like to point out that this also means that his t-shirt has the logo pre-flipped. What an absolute madlad.
- deleted 5y ago[deleted]
- cryo 5y agoI love these videos, it's the kind of no BS programming to press performance on modern computers. Also recommend the Handmade Hero series of him. We have computers which are ridiculous fast, but tend to write code which is freaking slow. It's sad that most programs could be 100x faster.
- nuerow 5y ago> We have computers which are ridiculous fast, but tend to write code which is freaking slow. It's sad that most programs could be 100x faster. I feel this sort of comment misses the whole point of going with code which is patently slower than alternatives. The main reason is that performance is a constraint but not a goal, and once it is good enough then there is absolutely nothing to be gained by wasting time on seeking performance gains. Meanwhile, the main resource in software development is man*hours. The faster you write software (add features, fix bugs, etc) the cheaper it is. Thus, software projects benefit the most by adopting and using technology which favour turnaround time, which means higher-level languages, generic full-featured frameworks, and code reuse. They are slow and bloated and not optimized, and they are used without optimization in mind. But they work and they work acceptably. Your client and project manager does not care if you go with a O(n2) implementation that you can whip out right now by reusing a package and has acceptable performance even if there is a O(n) alternative that requires you a few weeks to implement and forces you to test, debug, and maintain a lower level implementation. Performance is meaningless once it's good enough. It matters nothing if your browser wastes 1GB of RAM even though it could just use 100MB because practically everyone already has 8GB to begin with, and if would be foolish to waste resources prioritizing that if no one is willing to pay for that improvement. It matters nothing if your server has a relatively low throughput because it is wasting 10s of milliseconds doing nothing in each response if all your servers barely break 50% utilization. It matters nothing if your frontend is wasting 10s of milliseconds rendering a page if end users don't even notice any delay. If performance is good enough, work is focused on where it matters. We know it's possible to get formula1-level performance by using formula1-level of engineering and maintenance, but the world runs on Volkswagen hatchbacks.
- bsenftner 5y ago
- Zababa 5y agoI wonder how much performance is gained by having the code written by just one person. At work we have a reasonably large (16 MLOC) codebase. At this point I don't think it's possible for one person to do everything, especially while adding new features. So what we do is that we create relatively clean interfaces, and have people code mostly inside those interfaces. But every time we go through one of those interfaces, there's a performance hit.
- kjksf 5y agoIn this case: nothing. The fast renderer was written by one person in a few days. It's clearly a "few thousand loc" codebase, not "millions loc". The 100x slower renderer was also written by one person (or at most few). It really is the difference between programmers. It's also a good example that 10x programmers do exist, at least in certain situations. The Microsoft programmers are not dumb. They certainly are not cheap. And yet here we have one guy who can write code that is 10-100x faster, in just few days.
- Zababa 5y agoI don't think that's exactly true. It's not the same thing to write a piece of code as part of a whole system, vs rewriting that piece of code as an isolated part. > The 100x slower renderer was also written by one person (or at most few). The difference between one person and a few is massive in my experience. > It really is the difference between programmers. > It's also a good example that 10x programmers do exist, at least in certain situations. > The Microsoft programmers are not dumb. They certainly are not cheap. > And yet here we have one guy who can write code that is 10-100x faster, in just few days. I think it's a difference between incentives too. Microsoft programmers are not here to optimize for performance, but to push features, performance being one of them in some cases. For example, the research in file explorer is still painfully slow, probably because they have some other things to do. Many people could make it faster in a few days I guess. But these people aren't inside Microsoft being pressured to do other things. Software made to demonstrate how fast something can be is made in a very different environement and with very different incentives compared to almost all comercial software. For pretty much anything out there, someone can take it, isolate it and make it run 10-100x times faster I think. The thing is, in most organizations you don't have that kind of time.