1 00:00:00,480 --> 00:00:03,480 foreign 2 00:00:08,940 --> 00:00:13,139 So today we're going to talk about 3 00:00:10,760 --> 00:00:15,240 webassembly uh in particular we're going 4 00:00:13,139 --> 00:00:17,279 to talk about C python in webassembly 5 00:00:15,240 --> 00:00:19,260 who uses C python here 6 00:00:17,279 --> 00:00:21,660 yeah who uses a different implementation 7 00:00:19,260 --> 00:00:23,100 of python yeah yeah something like a lot 8 00:00:21,660 --> 00:00:25,260 to see by the people most of us you see 9 00:00:23,100 --> 00:00:27,539 python but in order to really understand 10 00:00:25,260 --> 00:00:29,099 what it means to run C python in 11 00:00:27,539 --> 00:00:31,080 webassembly we're going to dig a little 12 00:00:29,099 --> 00:00:34,140 bit more into UC python itself and how 13 00:00:31,080 --> 00:00:39,180 it works and but in particular how can I 14 00:00:34,140 --> 00:00:42,780 write code that runs on any machine so I 15 00:00:39,180 --> 00:00:44,520 have here an M1 Mac laptop so it has a 16 00:00:42,780 --> 00:00:46,680 different processor to the windows and 17 00:00:44,520 --> 00:00:48,420 Linux machine that I run at home and 18 00:00:46,680 --> 00:00:50,219 when I run stuff in the cloud and run 19 00:00:48,420 --> 00:00:51,960 stuff on Linux usually and so I'm 20 00:00:50,219 --> 00:00:54,719 dealing with different operating systems 21 00:00:51,960 --> 00:00:57,239 and different CPU architectures 22 00:00:54,719 --> 00:00:59,399 and there are two major approaches to 23 00:00:57,239 --> 00:01:01,440 like how to make code work across 24 00:00:59,399 --> 00:01:02,879 platforms the first approach which you 25 00:01:01,440 --> 00:01:05,339 are all familiar with is to use some 26 00:01:02,879 --> 00:01:07,680 kind of interpreter or engine like the 27 00:01:05,339 --> 00:01:09,540 python interpreter and so if I'm using 28 00:01:07,680 --> 00:01:11,820 if I'm writing code in Python I can 29 00:01:09,540 --> 00:01:13,500 write it once and as long as I'm running 30 00:01:11,820 --> 00:01:15,960 it on a machine that has python 31 00:01:13,500 --> 00:01:17,820 installed or there is a python 32 00:01:15,960 --> 00:01:20,460 interpreter there for me I can run the 33 00:01:17,820 --> 00:01:21,299 same code anywhere and it should just 34 00:01:20,460 --> 00:01:23,520 work 35 00:01:21,299 --> 00:01:26,520 uh and so if I take a little uh program 36 00:01:23,520 --> 00:01:29,159 like this uh it takes uh the current 37 00:01:26,520 --> 00:01:31,560 time uh the current local time it sort 38 00:01:29,159 --> 00:01:34,100 of formats that time it writes a little 39 00:01:31,560 --> 00:01:38,100 message into a file called time 40 00:01:34,100 --> 00:01:40,500 message.txt it prints to the the console 41 00:01:38,100 --> 00:01:43,020 um and at each of these steps it's 42 00:01:40,500 --> 00:01:44,579 interacting with the operating system it 43 00:01:43,020 --> 00:01:46,259 needs to go through the operating system 44 00:01:44,579 --> 00:01:48,840 to get the current time it needs to go 45 00:01:46,259 --> 00:01:50,939 through the operating system uh to write 46 00:01:48,840 --> 00:01:52,640 to a file and to write to stand it out 47 00:01:50,939 --> 00:01:55,619 and so 48 00:01:52,640 --> 00:01:58,380 where we can write this code in Python 49 00:01:55,619 --> 00:02:00,180 and python is handling that for us 50 00:01:58,380 --> 00:02:01,500 uh so we can write the code once and 51 00:02:00,180 --> 00:02:02,820 even though the operating the systems 52 00:02:01,500 --> 00:02:04,079 are different the file systems are 53 00:02:02,820 --> 00:02:06,119 different you're running it on a 54 00:02:04,079 --> 00:02:08,459 different machine uh this code will work 55 00:02:06,119 --> 00:02:10,140 and all of those places uh but that is 56 00:02:08,459 --> 00:02:12,300 because there is a different version of 57 00:02:10,140 --> 00:02:15,660 python for each one of these different 58 00:02:12,300 --> 00:02:18,120 platforms there's a python compiled for 59 00:02:15,660 --> 00:02:20,580 Windows as python compiled for Mac OS in 60 00:02:18,120 --> 00:02:22,739 fact the Mac OS 1 has two pythons 61 00:02:20,580 --> 00:02:24,480 because there's two different CPU 62 00:02:22,739 --> 00:02:28,020 architectures that need to account for 63 00:02:24,480 --> 00:02:30,060 and so we have for C python itself it 64 00:02:28,020 --> 00:02:32,520 takes the other approach approach to is 65 00:02:30,060 --> 00:02:34,739 to have some code that you compile a 66 00:02:32,520 --> 00:02:37,340 different version of that code to run on 67 00:02:34,739 --> 00:02:39,900 each different CPU and operating system 68 00:02:37,340 --> 00:02:43,260 and so we have C code which is our 69 00:02:39,900 --> 00:02:44,819 python code uh python C python itself we 70 00:02:43,260 --> 00:02:46,319 compile it to different executables for 71 00:02:44,819 --> 00:02:47,700 these different machines which means we 72 00:02:46,319 --> 00:02:50,580 need to have several different versions 73 00:02:47,700 --> 00:02:53,940 of python uh running around there and 74 00:02:50,580 --> 00:02:55,860 the way that python does this mostly is 75 00:02:53,940 --> 00:02:57,540 using the C standard Library you can 76 00:02:55,860 --> 00:03:00,120 write C code against this standard 77 00:02:57,540 --> 00:03:01,800 library and as long as there's an 78 00:03:00,120 --> 00:03:04,319 implementation of that standard library 79 00:03:01,800 --> 00:03:06,780 for each operating system you can 80 00:03:04,319 --> 00:03:08,280 compile see python so there's like one 81 00:03:06,780 --> 00:03:10,319 set of code for C Python and then it's 82 00:03:08,280 --> 00:03:11,519 compiled into different versions for 83 00:03:10,319 --> 00:03:12,800 different operating systems and 84 00:03:11,519 --> 00:03:15,720 platforms 85 00:03:12,800 --> 00:03:18,420 and so both of these approaches have 86 00:03:15,720 --> 00:03:21,000 some drawbacks to them either you need 87 00:03:18,420 --> 00:03:23,340 to have your language specific 88 00:03:21,000 --> 00:03:24,420 interpreter or engine on the machine 89 00:03:23,340 --> 00:03:27,720 that you're trying to run it on right 90 00:03:24,420 --> 00:03:29,580 python card on a mobile device probably 91 00:03:27,720 --> 00:03:31,620 doesn't have python installed you'd need 92 00:03:29,580 --> 00:03:32,760 to bundle The Interpreter with it and 93 00:03:31,620 --> 00:03:34,080 then you would need to have a different 94 00:03:32,760 --> 00:03:35,340 version for different platforms and 95 00:03:34,080 --> 00:03:36,840 different operating systems because 96 00:03:35,340 --> 00:03:38,459 you'd have a different implementation of 97 00:03:36,840 --> 00:03:40,099 the different compilation of the Python 98 00:03:38,459 --> 00:03:42,900 interpreter 99 00:03:40,099 --> 00:03:44,459 and even when you're writing code in C 100 00:03:42,900 --> 00:03:46,260 and compiling it for different platforms 101 00:03:44,459 --> 00:03:47,220 the C is not a library and the kind of 102 00:03:46,260 --> 00:03:48,959 different operating systems are quite 103 00:03:47,220 --> 00:03:51,239 different anyway and so you need to 104 00:03:48,959 --> 00:03:54,420 write code like this this is the C 105 00:03:51,239 --> 00:03:56,040 python open file implementation has a 106 00:03:54,420 --> 00:03:57,540 bunch of different like oh right if it's 107 00:03:56,040 --> 00:04:00,239 windows I have to do this other stuff oh 108 00:03:57,540 --> 00:04:02,760 if this particular like function is 109 00:04:00,239 --> 00:04:05,040 there I do this otherwise it's not 110 00:04:02,760 --> 00:04:07,200 um and so both of these approaches take 111 00:04:05,040 --> 00:04:10,680 a bit of work to have them work across 112 00:04:07,200 --> 00:04:13,799 platforms uh and so this talk is largely 113 00:04:10,680 --> 00:04:15,299 aspirational I have a dream one day in 114 00:04:13,799 --> 00:04:17,100 the future I want to be able to write 115 00:04:15,299 --> 00:04:18,239 any language not just python I want to 116 00:04:17,100 --> 00:04:19,620 be able to write whatever programming 117 00:04:18,239 --> 00:04:22,500 language I want I want to be able to 118 00:04:19,620 --> 00:04:24,720 build it into one thing one bundle one 119 00:04:22,500 --> 00:04:27,060 package something and have that package 120 00:04:24,720 --> 00:04:29,520 work on any machine right who would like 121 00:04:27,060 --> 00:04:32,580 this to be the case yes 122 00:04:29,520 --> 00:04:34,199 right yes computer Esperanto that's a 123 00:04:32,580 --> 00:04:36,240 good way to put it um I want to be able 124 00:04:34,199 --> 00:04:37,919 to like choose my language and not have 125 00:04:36,240 --> 00:04:40,199 to worry about oh I have a right Java I 126 00:04:37,919 --> 00:04:41,460 have to make sure there's a jvm there if 127 00:04:40,199 --> 00:04:43,080 I write JavaScript I need to have a 128 00:04:41,460 --> 00:04:45,060 JavaScript engine 129 00:04:43,080 --> 00:04:47,160 um if I write in Rust I need to compile 130 00:04:45,060 --> 00:04:48,120 different versions for every platform I 131 00:04:47,160 --> 00:04:50,460 don't want to have to deal with any of 132 00:04:48,120 --> 00:04:52,139 that I want it to all just work which 133 00:04:50,460 --> 00:04:53,280 would be great 134 00:04:52,139 --> 00:04:55,979 um so I actually have a second dream as 135 00:04:53,280 --> 00:04:56,940 well this is a very aspirational talk 136 00:04:55,979 --> 00:04:59,220 um 137 00:04:56,940 --> 00:05:00,960 and for my other for my other dream to 138 00:04:59,220 --> 00:05:02,940 explain this I need to ask you all the 139 00:05:00,960 --> 00:05:04,620 question okay we're gonna do a show of 140 00:05:02,940 --> 00:05:06,540 hands I need you to answer this question 141 00:05:04,620 --> 00:05:08,340 honestly 142 00:05:06,540 --> 00:05:10,979 do you ever run code locally that you 143 00:05:08,340 --> 00:05:13,440 don't really trust 144 00:05:10,979 --> 00:05:15,479 yes okay that's a lot of hands 145 00:05:13,440 --> 00:05:17,520 um I also do this 146 00:05:15,479 --> 00:05:19,440 um I might do something like oh I cloned 147 00:05:17,520 --> 00:05:21,660 some git repo from some random internet 148 00:05:19,440 --> 00:05:23,460 stranger and then I will build and run 149 00:05:21,660 --> 00:05:25,020 that code I might if install some 150 00:05:23,460 --> 00:05:26,940 package I've never heard before heard of 151 00:05:25,020 --> 00:05:29,160 before there was 152 00:05:26,940 --> 00:05:31,740 what was that 153 00:05:29,160 --> 00:05:33,240 oh yeah I forgot sooner yeah see I don't 154 00:05:31,740 --> 00:05:34,620 know that so like there's a limit to how 155 00:05:33,240 --> 00:05:37,080 much damage this can do if you don't use 156 00:05:34,620 --> 00:05:38,280 Suitor if you do use sudo ah yeah all 157 00:05:37,080 --> 00:05:38,940 bets are off 158 00:05:38,280 --> 00:05:41,940 um 159 00:05:38,940 --> 00:05:43,440 so uh the The Bash one for like running 160 00:05:41,940 --> 00:05:46,080 an install script that's from The 161 00:05:43,440 --> 00:05:47,699 Homebrew installation instructions 162 00:05:46,080 --> 00:05:49,259 um just like oh yeah let's just run the 163 00:05:47,699 --> 00:05:50,699 script in my terminal 164 00:05:49,259 --> 00:05:53,580 um so I have done all of these things 165 00:05:50,699 --> 00:05:55,440 right and this is this is risky Behavior 166 00:05:53,580 --> 00:05:58,080 this is risky behavior that we all do 167 00:05:55,440 --> 00:06:01,020 right these programs don't even need 168 00:05:58,080 --> 00:06:03,360 pseudo access to say read the folder 169 00:06:01,020 --> 00:06:04,979 where your SSH keys are or your maybe 170 00:06:03,360 --> 00:06:06,720 your AWS credentials are sitting in a 171 00:06:04,979 --> 00:06:08,820 credentials file there maybe you have 172 00:06:06,720 --> 00:06:11,039 API access tokens in your environment 173 00:06:08,820 --> 00:06:12,180 variables right you're running programs 174 00:06:11,039 --> 00:06:14,400 all the time where if there was 175 00:06:12,180 --> 00:06:15,840 malicious code in there like it could it 176 00:06:14,400 --> 00:06:17,759 could do some damage 177 00:06:15,840 --> 00:06:19,440 right 178 00:06:17,759 --> 00:06:21,840 um so my second dream 179 00:06:19,440 --> 00:06:24,120 that I want to be able to easily limit a 180 00:06:21,840 --> 00:06:26,759 program's access to just what it needs 181 00:06:24,120 --> 00:06:28,380 and nothing else very fine-grained 182 00:06:26,759 --> 00:06:30,960 permissions like yes you can write files 183 00:06:28,380 --> 00:06:32,280 but like only to this folder or yes you 184 00:06:30,960 --> 00:06:34,620 can connect to the internet but only 185 00:06:32,280 --> 00:06:36,620 this particular like port or this 186 00:06:34,620 --> 00:06:40,440 particular address 187 00:06:36,620 --> 00:06:42,120 so we kind of already have this a little 188 00:06:40,440 --> 00:06:45,360 bit 189 00:06:42,120 --> 00:06:47,940 um you already run untrusted code in a 190 00:06:45,360 --> 00:06:49,380 reasonably secure way every day and I'm 191 00:06:47,940 --> 00:06:50,699 not talking about people here who are 192 00:06:49,380 --> 00:06:52,740 like very security conscious and like 193 00:06:50,699 --> 00:06:55,139 run everything in a virtual machine 194 00:06:52,740 --> 00:06:57,840 um you all run untrusted code securely 195 00:06:55,139 --> 00:07:00,660 every day how do you do that 196 00:06:57,840 --> 00:07:02,039 browsers yes exactly web browsers web 197 00:07:00,660 --> 00:07:04,680 browsers are great they're basically 198 00:07:02,039 --> 00:07:06,780 running untrusted code machines you go 199 00:07:04,680 --> 00:07:09,660 to some random URL and is pulling all 200 00:07:06,780 --> 00:07:11,580 this all this code and just running it 201 00:07:09,660 --> 00:07:14,160 um and it has sandboxed that it is 202 00:07:11,580 --> 00:07:16,500 secure it is built in a way that like 203 00:07:14,160 --> 00:07:18,900 that code can't wreak havoc on your 204 00:07:16,500 --> 00:07:22,560 machine and that's that's really cool 205 00:07:18,900 --> 00:07:25,139 but not all apps or web apps Katie like 206 00:07:22,560 --> 00:07:27,599 yes not all apps are web apps uh we want 207 00:07:25,139 --> 00:07:29,819 to be able to run other things but still 208 00:07:27,599 --> 00:07:32,940 get those same kinds of advantages 209 00:07:29,819 --> 00:07:36,539 and so if we've cast your minds back to 210 00:07:32,940 --> 00:07:38,400 2013 uh the Harlem Shake was a thing if 211 00:07:36,539 --> 00:07:39,120 you remember that 212 00:07:38,400 --> 00:07:41,300 um 213 00:07:39,120 --> 00:07:44,940 Mozilla introduced not webassembly 214 00:07:41,300 --> 00:07:46,440 asm.js who's heard of asm.js hey lots of 215 00:07:44,940 --> 00:07:49,520 people that's great 216 00:07:46,440 --> 00:07:52,620 um it's essentially like a weird subset 217 00:07:49,520 --> 00:07:55,560 munging of JavaScript 218 00:07:52,620 --> 00:07:58,319 um you could take JavaScript and label 219 00:07:55,560 --> 00:08:00,419 certain functions as use ASM and that 220 00:07:58,319 --> 00:08:02,300 would signal to the browser that this is 221 00:08:00,419 --> 00:08:05,520 not normal JavaScript this is like 222 00:08:02,300 --> 00:08:08,220 heavily optimizable JavaScript it 223 00:08:05,520 --> 00:08:10,440 doesn't use normal Heap variables it 224 00:08:08,220 --> 00:08:14,520 will store the Heap in like a byte array 225 00:08:10,440 --> 00:08:16,259 of its own and it will enforce the types 226 00:08:14,520 --> 00:08:19,319 on various things essentially like it's 227 00:08:16,259 --> 00:08:21,479 changing JavaScript into a set of 228 00:08:19,319 --> 00:08:23,639 functions that can be optimized for most 229 00:08:21,479 --> 00:08:25,800 CPUs that can be optimized really really 230 00:08:23,639 --> 00:08:29,039 efficiently for the sort of common 231 00:08:25,800 --> 00:08:31,500 features that most CPUs have right like 232 00:08:29,039 --> 00:08:33,180 32-bit integers is a lot easier than 233 00:08:31,500 --> 00:08:35,700 dealing with like JavaScript numbers 234 00:08:33,180 --> 00:08:37,620 which might be an integer it might be a 235 00:08:35,700 --> 00:08:40,140 double we don't really know until we run 236 00:08:37,620 --> 00:08:44,459 it so this was was able to be run 237 00:08:40,140 --> 00:08:46,380 extremely fast on the browser now this 238 00:08:44,459 --> 00:08:48,959 is really ugly code you do not want to 239 00:08:46,380 --> 00:08:51,660 be writing this code yourself it was 240 00:08:48,959 --> 00:08:54,180 intended to be a compilation Target so 241 00:08:51,660 --> 00:08:57,000 we could write code in C or some other 242 00:08:54,180 --> 00:08:59,100 language and compile it into JavaScript 243 00:08:57,000 --> 00:09:00,540 and it would run slower than it would 244 00:08:59,100 --> 00:09:03,660 normally normal machine but actually 245 00:09:00,540 --> 00:09:06,000 reasonably fast and this is how the 246 00:09:03,660 --> 00:09:07,620 first time we had C python working in a 247 00:09:06,000 --> 00:09:11,700 browser worked you could compile C 248 00:09:07,620 --> 00:09:15,779 Python and run it as JavaScript code in 249 00:09:11,700 --> 00:09:17,760 the browser and it was maybe twice as 250 00:09:15,779 --> 00:09:19,620 slow or as like normally running it two 251 00:09:17,760 --> 00:09:21,660 or three times or so but it was actually 252 00:09:19,620 --> 00:09:23,700 usable and so if you think running 253 00:09:21,660 --> 00:09:25,260 python in the browser is a new exciting 254 00:09:23,700 --> 00:09:26,940 thing it's actually been done for 10 255 00:09:25,260 --> 00:09:30,839 years now 256 00:09:26,940 --> 00:09:34,080 um but this had some downsides to it so 257 00:09:30,839 --> 00:09:36,600 particularly trying to write this kind 258 00:09:34,080 --> 00:09:38,399 of heavily optimizable JavaScript but 259 00:09:36,600 --> 00:09:40,860 still maintain backwards compatibility 260 00:09:38,399 --> 00:09:42,360 just in case the browser didn't have the 261 00:09:40,860 --> 00:09:43,740 optimizations built in it still had to 262 00:09:42,360 --> 00:09:46,019 work 263 00:09:43,740 --> 00:09:47,580 um that is quite difficult trying to 264 00:09:46,019 --> 00:09:50,160 make it fast and also compatible with 265 00:09:47,580 --> 00:09:53,399 JavaScript but the bigger problem was 266 00:09:50,160 --> 00:09:54,839 really really huge piles of JavaScript 267 00:09:53,399 --> 00:09:57,779 that you would have to download to be 268 00:09:54,839 --> 00:10:00,300 able to run it okay so python C python 269 00:09:57,779 --> 00:10:03,060 wasn't super usable in this form because 270 00:10:00,300 --> 00:10:05,399 you had this huge download size to try 271 00:10:03,060 --> 00:10:08,100 and run C python in the browser 272 00:10:05,399 --> 00:10:09,899 uh so webassembly was invented as they 273 00:10:08,100 --> 00:10:11,580 were sort of starting to discuss maybe 274 00:10:09,899 --> 00:10:13,740 we can create some kind of compact 275 00:10:11,580 --> 00:10:15,480 binary format for this JavaScript code 276 00:10:13,740 --> 00:10:17,220 and then once you've sort of breaking 277 00:10:15,480 --> 00:10:19,200 compatibility with JavaScript you might 278 00:10:17,220 --> 00:10:21,600 as well like invent a whole new system 279 00:10:19,200 --> 00:10:23,220 anyway so first version of webassembly 280 00:10:21,600 --> 00:10:24,839 was like built on what was learned from 281 00:10:23,220 --> 00:10:28,140 asm.js 282 00:10:24,839 --> 00:10:29,640 sir if you hear me say wasm and 283 00:10:28,140 --> 00:10:31,019 webassembly those are interchangeable 284 00:10:29,640 --> 00:10:32,820 that is the same thing it's not an 285 00:10:31,019 --> 00:10:34,920 acronym plasm is just short for 286 00:10:32,820 --> 00:10:37,320 webassembly okay 287 00:10:34,920 --> 00:10:40,380 so we can take code in these various 288 00:10:37,320 --> 00:10:42,899 different languages and compile it to a 289 00:10:40,380 --> 00:10:44,220 little dot wasm binary file which is the 290 00:10:42,899 --> 00:10:46,500 compact format 291 00:10:44,220 --> 00:10:49,079 it's very fast to read and load it's 292 00:10:46,500 --> 00:10:52,440 very fast startup time 293 00:10:49,079 --> 00:10:54,839 um and this code will run in a browser 294 00:10:52,440 --> 00:10:56,820 in the browser's webassembly engine this 295 00:10:54,839 --> 00:10:58,440 is a standard across all browsers all 296 00:10:56,820 --> 00:11:00,660 browsers support this now 297 00:10:58,440 --> 00:11:02,940 uh and the binary files are way smaller 298 00:11:00,660 --> 00:11:06,060 than they were for asm.js uh which is 299 00:11:02,940 --> 00:11:08,220 great so webassembly has a text format 300 00:11:06,060 --> 00:11:09,600 as well you don't usually write this 301 00:11:08,220 --> 00:11:11,040 because again you just compile other 302 00:11:09,600 --> 00:11:12,660 code to webassembly but it's used for 303 00:11:11,040 --> 00:11:14,579 debugging and for Learning and to sort 304 00:11:12,660 --> 00:11:15,959 of explain what webassembly is actually 305 00:11:14,579 --> 00:11:18,899 doing under the hood 306 00:11:15,959 --> 00:11:21,839 now this is not actually an Assembly 307 00:11:18,899 --> 00:11:23,820 Language it is a stack based virtual 308 00:11:21,839 --> 00:11:25,980 machine right it is its own kind of 309 00:11:23,820 --> 00:11:28,740 interpreter but one that is intended to 310 00:11:25,980 --> 00:11:30,660 be incredibly optimizable for what most 311 00:11:28,740 --> 00:11:32,459 CPUs are capable of and it's getting 312 00:11:30,660 --> 00:11:34,740 faster all the time as they're adding 313 00:11:32,459 --> 00:11:36,720 more functionality for sort of simdi and 314 00:11:34,740 --> 00:11:39,420 like different CPU instructions that can 315 00:11:36,720 --> 00:11:40,560 be used uh to make things run faster and 316 00:11:39,420 --> 00:11:42,779 faster 317 00:11:40,560 --> 00:11:44,399 in this example this is just a little 318 00:11:42,779 --> 00:11:45,959 function that takes two numbers and adds 319 00:11:44,399 --> 00:11:49,380 them together but you can see it's 320 00:11:45,959 --> 00:11:52,279 calling the console log function and 321 00:11:49,380 --> 00:11:54,720 this is because in a browser you can 322 00:11:52,279 --> 00:11:57,360 JavaScript can call webassembly 323 00:11:54,720 --> 00:11:59,040 functions invoke webassembly scripts and 324 00:11:57,360 --> 00:12:00,959 webassembly can call JavaScript 325 00:11:59,040 --> 00:12:02,640 functions if it was built to have those 326 00:12:00,959 --> 00:12:03,899 functions imported into webassembly so 327 00:12:02,640 --> 00:12:05,880 they can sort of call functions back and 328 00:12:03,899 --> 00:12:07,860 forth but they are separate instances 329 00:12:05,880 --> 00:12:09,860 they have separate various separate 330 00:12:07,860 --> 00:12:11,700 Stacks separate variables 331 00:12:09,860 --> 00:12:13,680 passing large amounts of information 332 00:12:11,700 --> 00:12:15,000 between the two means copying them from 333 00:12:13,680 --> 00:12:16,380 one to another 334 00:12:15,000 --> 00:12:19,800 okay 335 00:12:16,380 --> 00:12:23,339 so back to python okay we want to make C 336 00:12:19,800 --> 00:12:25,140 python work in webassembly and I'm going 337 00:12:23,339 --> 00:12:26,700 to preface this with part of the point 338 00:12:25,140 --> 00:12:28,320 of this talk is to talk about that there 339 00:12:26,700 --> 00:12:30,600 are more than there's more than one way 340 00:12:28,320 --> 00:12:32,040 to compile see python to webassembly and 341 00:12:30,600 --> 00:12:33,180 it means very different things in 342 00:12:32,040 --> 00:12:35,220 different circumstances so we're going 343 00:12:33,180 --> 00:12:37,440 to go through two different ways to 344 00:12:35,220 --> 00:12:39,240 compile C python to webassembly that are 345 00:12:37,440 --> 00:12:42,600 quite different to each other 346 00:12:39,240 --> 00:12:44,760 the first one is compiling C python with 347 00:12:42,600 --> 00:12:46,740 M scripting now if you're used to 348 00:12:44,760 --> 00:12:49,500 compiling things with C you have your C 349 00:12:46,740 --> 00:12:51,959 file you run GCC or something and it 350 00:12:49,500 --> 00:12:53,100 gives you a binary file M scripting is 351 00:12:51,959 --> 00:12:57,120 designed to kind of drop in there and 352 00:12:53,100 --> 00:12:59,760 you just say EMCC instead of GCC and it 353 00:12:57,120 --> 00:13:01,800 will spit out a Javascript file and a 354 00:12:59,760 --> 00:13:04,139 webassembly file 355 00:13:01,800 --> 00:13:06,300 and we're going to use this we're going 356 00:13:04,139 --> 00:13:07,380 to do a live demo and this is the python 357 00:13:06,300 --> 00:13:08,940 code that we're going to run it's the 358 00:13:07,380 --> 00:13:11,820 same as before it's reading the local 359 00:13:08,940 --> 00:13:12,899 time and it's writing it to a file and 360 00:13:11,820 --> 00:13:15,060 the file is called time 361 00:13:12,899 --> 00:13:18,540 underscoremessage.txt 362 00:13:15,060 --> 00:13:21,779 okay live Denver time so 363 00:13:18,540 --> 00:13:25,200 when we run a python see python built 364 00:13:21,779 --> 00:13:27,899 within scriptin in the browser so the 365 00:13:25,200 --> 00:13:29,700 parts here that are built by m scripting 366 00:13:27,899 --> 00:13:33,120 so you take C Python and it spits out 367 00:13:29,700 --> 00:13:34,800 this python.js file which is just a 368 00:13:33,120 --> 00:13:36,300 JavaScript sort of wrapper that's the 369 00:13:34,800 --> 00:13:38,180 thing that has the API that you can call 370 00:13:36,300 --> 00:13:40,740 to start running python as is 371 00:13:38,180 --> 00:13:43,440 python.wasm file which is our most of 372 00:13:40,740 --> 00:13:45,180 where the C code actually goes and this 373 00:13:43,440 --> 00:13:46,800 is python.data which is essentially all 374 00:13:45,180 --> 00:13:49,200 the files that python needs to be able 375 00:13:46,800 --> 00:13:50,639 to run in the browser like Library files 376 00:13:49,200 --> 00:13:52,800 and python files that are part of the 377 00:13:50,639 --> 00:13:55,880 standard Library uh go into that sort of 378 00:13:52,800 --> 00:13:59,459 data package here now this 379 00:13:55,880 --> 00:14:01,860 python.worker.js and the python.html I 380 00:13:59,459 --> 00:14:03,480 wrote those myself largely I wrote the 381 00:14:01,860 --> 00:14:07,320 first version someone else added it it's 382 00:14:03,480 --> 00:14:10,560 in the C python repo there as a way to 383 00:14:07,320 --> 00:14:12,779 kind of test out your M scripting python 384 00:14:10,560 --> 00:14:15,060 so this is our python code that I 385 00:14:12,779 --> 00:14:17,399 pre-loaded in there that reads the 386 00:14:15,060 --> 00:14:19,380 current time and writes file and if I 387 00:14:17,399 --> 00:14:23,220 run the reple here I can just use the 388 00:14:19,380 --> 00:14:25,019 repo like print hi it works as as a 389 00:14:23,220 --> 00:14:27,060 python Ripple would 390 00:14:25,019 --> 00:14:28,200 um the the terminal itself and the text 391 00:14:27,060 --> 00:14:30,899 box like that's all just normal 392 00:14:28,200 --> 00:14:33,300 JavaScript web app stuff and then it's 393 00:14:30,899 --> 00:14:35,220 calling into the webassembly to run 394 00:14:33,300 --> 00:14:37,440 python okay so I can stop that running 395 00:14:35,220 --> 00:14:38,880 and by then in this case is running in a 396 00:14:37,440 --> 00:14:42,360 web worker so it's actually running in a 397 00:14:38,880 --> 00:14:44,579 separate thread okay if I clear this 398 00:14:42,360 --> 00:14:47,519 and I run the python code it just says 399 00:14:44,579 --> 00:14:49,019 message written to file okay 400 00:14:47,519 --> 00:14:51,300 we're in a browser like where is that 401 00:14:49,019 --> 00:14:53,639 file what file did it just write a file 402 00:14:51,300 --> 00:14:55,680 like what is going on here 403 00:14:53,639 --> 00:14:58,199 um and we can kind of see a little bit 404 00:14:55,680 --> 00:15:01,440 what's going on if we like we can delete 405 00:14:58,199 --> 00:15:03,120 this and we can say import 406 00:15:01,440 --> 00:15:04,380 OS we're importing or where is the 407 00:15:03,120 --> 00:15:07,199 operating system like what is going on 408 00:15:04,380 --> 00:15:08,820 uh OS dot Lister 409 00:15:07,199 --> 00:15:10,320 if I remember that I'm typing this 410 00:15:08,820 --> 00:15:12,000 correctly 411 00:15:10,320 --> 00:15:14,180 oh I need to print that that would make 412 00:15:12,000 --> 00:15:14,180 sense 413 00:15:15,720 --> 00:15:21,120 run okay we do have a file system there 414 00:15:18,720 --> 00:15:22,620 are some folders there 415 00:15:21,120 --> 00:15:24,360 um there's a temp home there's also a 416 00:15:22,620 --> 00:15:27,480 main.pi which was the code I was running 417 00:15:24,360 --> 00:15:29,899 before and time underscoremessage.txt is 418 00:15:27,480 --> 00:15:32,459 there so if we could say it feels open 419 00:15:29,899 --> 00:15:34,680 it's just in like the top of my root 420 00:15:32,459 --> 00:15:38,279 directory I guess uh 421 00:15:34,680 --> 00:15:38,279 time message.txt 422 00:15:39,240 --> 00:15:43,920 printf dot read 423 00:15:41,519 --> 00:15:46,500 and we run that okay it says the current 424 00:15:43,920 --> 00:15:48,180 time is 10 51 so you can tell this is a 425 00:15:46,500 --> 00:15:50,220 live demo it is actually well it was 10 426 00:15:48,180 --> 00:15:53,220 51 when I wrote the file 427 00:15:50,220 --> 00:15:55,139 um the string format time part isn't 428 00:15:53,220 --> 00:15:57,839 very like cross-platform consistent 429 00:15:55,139 --> 00:16:00,600 generally uh so the AM PM part didn't 430 00:15:57,839 --> 00:16:03,060 work uh but hey we have we have written 431 00:16:00,600 --> 00:16:06,120 a file uh so what is going on with this 432 00:16:03,060 --> 00:16:08,100 file uh that we wrote so cast your minds 433 00:16:06,120 --> 00:16:10,260 back to when we're talking about C uh 434 00:16:08,100 --> 00:16:12,420 and C python calls functions in the C 435 00:16:10,260 --> 00:16:13,500 standard library and that c standard 436 00:16:12,420 --> 00:16:15,060 Library kind of works differently on 437 00:16:13,500 --> 00:16:18,120 different operating systems to implement 438 00:16:15,060 --> 00:16:20,519 that library in mm scripting 439 00:16:18,120 --> 00:16:22,740 and scriptn provides a JavaScript 440 00:16:20,519 --> 00:16:25,380 implementation of the C standard Library 441 00:16:22,740 --> 00:16:27,060 among other things but mostly that and 442 00:16:25,380 --> 00:16:27,959 that implementation of the C standard 443 00:16:27,060 --> 00:16:30,600 Library 444 00:16:27,959 --> 00:16:34,560 by default uses an in-memory file system 445 00:16:30,600 --> 00:16:36,360 that's in the browser so my file system 446 00:16:34,560 --> 00:16:38,639 that I'm reading and writing to here is 447 00:16:36,360 --> 00:16:40,980 just in memory in this browser if I 448 00:16:38,639 --> 00:16:41,880 refresh the tab everything in that will 449 00:16:40,980 --> 00:16:43,680 be gone 450 00:16:41,880 --> 00:16:46,560 okay 451 00:16:43,680 --> 00:16:48,360 um so what can't webassembly do at least 452 00:16:46,560 --> 00:16:50,339 within script and running in the browser 453 00:16:48,360 --> 00:16:51,720 now we can get random numbers we can get 454 00:16:50,339 --> 00:16:53,040 the system clock time we can do quite a 455 00:16:51,720 --> 00:16:55,019 lot of different operating systemy 456 00:16:53,040 --> 00:16:57,779 things reading and writing the local 457 00:16:55,019 --> 00:16:59,160 file system well it's got this in-memory 458 00:16:57,779 --> 00:17:00,899 file system so you can kind of simulate 459 00:16:59,160 --> 00:17:02,820 that but it's not actually my files on 460 00:17:00,899 --> 00:17:05,640 my local machine because browsers can't 461 00:17:02,820 --> 00:17:07,319 do that now there is a new web API that 462 00:17:05,640 --> 00:17:09,059 lets you access local file systems it 463 00:17:07,319 --> 00:17:10,799 pops up a thing it gives you permission 464 00:17:09,059 --> 00:17:14,160 to a particular directory 465 00:17:10,799 --> 00:17:17,280 but uh you can use that from in 466 00:17:14,160 --> 00:17:20,040 scripting but it has an async only API 467 00:17:17,280 --> 00:17:22,439 because that JavaScript API is async so 468 00:17:20,040 --> 00:17:24,839 you can't do synchronous file system 469 00:17:22,439 --> 00:17:27,120 reads and writes to that because it's 470 00:17:24,839 --> 00:17:29,400 asynchronous so it's quite difficult it 471 00:17:27,120 --> 00:17:31,200 is possible to access the local file 472 00:17:29,400 --> 00:17:31,980 system but from C python currently you 473 00:17:31,200 --> 00:17:34,620 can't 474 00:17:31,980 --> 00:17:36,419 also sockets and networking like 475 00:17:34,620 --> 00:17:38,460 generally aren't supported in a browser 476 00:17:36,419 --> 00:17:41,340 anyway so these turn out turn out to be 477 00:17:38,460 --> 00:17:43,200 mostly limitations of the browser and 478 00:17:41,340 --> 00:17:44,880 what you can and can't do in a browser 479 00:17:43,200 --> 00:17:47,100 rather than limitations of what you can 480 00:17:44,880 --> 00:17:48,840 and can't do with webassembly itself 481 00:17:47,100 --> 00:17:50,400 okay 482 00:17:48,840 --> 00:17:52,559 um the cool thing is though am scripting 483 00:17:50,400 --> 00:17:55,320 does support sdl2 so you can do 484 00:17:52,559 --> 00:17:57,900 graphical interfaces audio joystick and 485 00:17:55,320 --> 00:18:02,280 keyboard and mouse inputs and have that 486 00:17:57,900 --> 00:18:05,100 all work uh and uh PMP Dash B on GitHub 487 00:18:02,280 --> 00:18:07,980 has done amazing work to support Pi game 488 00:18:05,100 --> 00:18:10,559 in the browser so you can take Pi game 489 00:18:07,980 --> 00:18:13,020 games and run them in the browser 490 00:18:10,559 --> 00:18:14,760 because inscript and supports sdl2 which 491 00:18:13,020 --> 00:18:15,960 happens to be what pygame uses now if 492 00:18:14,760 --> 00:18:18,419 there's a different game engine that 493 00:18:15,960 --> 00:18:21,240 doesn't use sdl yeah good luck 494 00:18:18,419 --> 00:18:24,620 um but Pi game happens uh happens to 495 00:18:21,240 --> 00:18:26,880 work so highly recommend checking out uh 496 00:18:24,620 --> 00:18:28,740 pygame.web.github.ao for a bunch of 497 00:18:26,880 --> 00:18:31,080 different Pi game games running in the 498 00:18:28,740 --> 00:18:34,559 browser there the other shout out goes 499 00:18:31,080 --> 00:18:36,299 to piadide which is much easier to use 500 00:18:34,559 --> 00:18:38,940 than trying to compile C python to 501 00:18:36,299 --> 00:18:41,039 encrypt them yourself it's packaged up 502 00:18:38,940 --> 00:18:43,080 it's very easy to integrate python into 503 00:18:41,039 --> 00:18:44,580 a web app using piadite it actually 504 00:18:43,080 --> 00:18:47,340 supports installing a bunch of pip 505 00:18:44,580 --> 00:18:50,520 packages as well including packages with 506 00:18:47,340 --> 00:18:52,500 native code pandas numpy lots of the 507 00:18:50,520 --> 00:18:54,600 data science packages will just work in 508 00:18:52,500 --> 00:18:56,460 a browser using piadite people have made 509 00:18:54,600 --> 00:18:57,840 jupyter notebooks but like entirely in 510 00:18:56,460 --> 00:18:59,520 the browser without needing a server 511 00:18:57,840 --> 00:19:02,460 it's very cool 512 00:18:59,520 --> 00:19:04,020 okay going back to the two dreams that I 513 00:19:02,460 --> 00:19:05,400 had I want to be able to write in any 514 00:19:04,020 --> 00:19:07,340 language compile it once and have it 515 00:19:05,400 --> 00:19:10,260 work on any machine or operating system 516 00:19:07,340 --> 00:19:12,179 sort of yes I guess if it's in a web 517 00:19:10,260 --> 00:19:13,740 browser it works 518 00:19:12,179 --> 00:19:15,360 um I want to easily limit a program's 519 00:19:13,740 --> 00:19:18,360 access to just what it needs and nothing 520 00:19:15,360 --> 00:19:20,700 else well also sort of like it's limited 521 00:19:18,360 --> 00:19:21,900 it's safe it's secure but also I can't 522 00:19:20,700 --> 00:19:23,820 access a whole bunch of things that I 523 00:19:21,900 --> 00:19:25,140 might want to actually have my code 524 00:19:23,820 --> 00:19:26,760 access 525 00:19:25,140 --> 00:19:28,740 sorry it's kind of halfway there not 526 00:19:26,760 --> 00:19:30,960 quite there yet 527 00:19:28,740 --> 00:19:33,600 um but webassembly was built as a web 528 00:19:30,960 --> 00:19:35,340 standard for browsers to use but once it 529 00:19:33,600 --> 00:19:37,620 was built and once it was standardized 530 00:19:35,340 --> 00:19:39,059 once people started using it I started 531 00:19:37,620 --> 00:19:41,220 to think well webassembly is 532 00:19:39,059 --> 00:19:42,660 standardized it's language independent 533 00:19:41,220 --> 00:19:44,220 can run basically anything on it because 534 00:19:42,660 --> 00:19:45,299 you can compile to it it is 535 00:19:44,220 --> 00:19:46,620 cross-platform and we have 536 00:19:45,299 --> 00:19:48,539 implementations of it for several 537 00:19:46,620 --> 00:19:50,400 different platforms already it's sandbox 538 00:19:48,539 --> 00:19:52,500 and secure and it's pretty much very 539 00:19:50,400 --> 00:19:54,960 it's very close to Native speeds uh 540 00:19:52,500 --> 00:19:57,419 depending on what you're doing 541 00:19:54,960 --> 00:19:59,640 what if we had a standalone webassembly 542 00:19:57,419 --> 00:20:02,460 engine that we could run anywhere 543 00:19:59,640 --> 00:20:04,380 including outside of a browser wouldn't 544 00:20:02,460 --> 00:20:05,760 that be cool we could just kind of build 545 00:20:04,380 --> 00:20:06,600 stuff for webassembly and just run it 546 00:20:05,760 --> 00:20:08,880 anywhere 547 00:20:06,600 --> 00:20:10,440 uh and these things exist but you can't 548 00:20:08,880 --> 00:20:14,100 just kind of run webassembly by itself 549 00:20:10,440 --> 00:20:15,419 if it can't do anything like read and 550 00:20:14,100 --> 00:20:17,160 write the file system or access the 551 00:20:15,419 --> 00:20:18,900 network still needs to be able to do 552 00:20:17,160 --> 00:20:20,280 those things and if we're going to run 553 00:20:18,900 --> 00:20:23,220 it everywhere we need some kind of 554 00:20:20,280 --> 00:20:25,500 standardized API to be able to do those 555 00:20:23,220 --> 00:20:29,700 things uh hence there is a new standard 556 00:20:25,500 --> 00:20:31,980 YZ the web assembly system interface 557 00:20:29,700 --> 00:20:33,240 and this is a center that is in active 558 00:20:31,980 --> 00:20:35,100 development there's currently like 559 00:20:33,240 --> 00:20:37,020 preview zero and preview one and they're 560 00:20:35,100 --> 00:20:39,120 working on preview two 561 00:20:37,020 --> 00:20:41,700 um but people are already using it so I 562 00:20:39,120 --> 00:20:44,039 could have a webassembly program and I 563 00:20:41,700 --> 00:20:46,559 have this API that lets me access common 564 00:20:44,039 --> 00:20:48,480 operating system things it's not the 565 00:20:46,559 --> 00:20:50,700 same as the CPC API because we don't 566 00:20:48,480 --> 00:20:53,580 want to deal with all the Legacy things 567 00:20:50,700 --> 00:20:55,980 um but it kind of follows that a little 568 00:20:53,580 --> 00:20:58,440 bit as well so I can read files write 569 00:20:55,980 --> 00:21:00,720 files I can get the system time I can 570 00:20:58,440 --> 00:21:02,940 access the network and it's all going 571 00:21:00,720 --> 00:21:04,980 through this wazzy API 572 00:21:02,940 --> 00:21:07,799 and so if I have 573 00:21:04,980 --> 00:21:09,419 uh and there's an implementation of the 574 00:21:07,799 --> 00:21:11,640 C standard Library 575 00:21:09,419 --> 00:21:14,340 on the Wazi IPI so I can use the C 576 00:21:11,640 --> 00:21:16,320 standard library in my normal C code and 577 00:21:14,340 --> 00:21:19,140 when I build it for webassembly it's 578 00:21:16,320 --> 00:21:21,960 built to use the Wazi API underneath 579 00:21:19,140 --> 00:21:23,880 okay so wasm time is a standalone 580 00:21:21,960 --> 00:21:27,360 webassembly engine that supports the 581 00:21:23,880 --> 00:21:28,860 Wazi system the the wazzy interface and 582 00:21:27,360 --> 00:21:31,380 so in theory I could just kind of say 583 00:21:28,860 --> 00:21:34,080 wasm time python.wasm and I'd be able to 584 00:21:31,380 --> 00:21:35,520 run python uh like this uh and I would 585 00:21:34,080 --> 00:21:38,940 be able to run whatever python code I 586 00:21:35,520 --> 00:21:40,500 wanted uh and this was python.wasm would 587 00:21:38,940 --> 00:21:42,480 work on any machine as long as I have 588 00:21:40,500 --> 00:21:45,539 wasm time or a different webassembly 589 00:21:42,480 --> 00:21:47,820 engine uh installed on that machine 590 00:21:45,539 --> 00:21:50,460 which would be cool but it doesn't work 591 00:21:47,820 --> 00:21:54,000 exactly as easily as this 592 00:21:50,460 --> 00:21:56,400 um so if I wanted to build python uh for 593 00:21:54,000 --> 00:21:58,020 Wazi it's a little bit more complicated 594 00:21:56,400 --> 00:22:00,600 than building from scripting it hasn't 595 00:21:58,020 --> 00:22:01,980 had as much sort of work put into making 596 00:22:00,600 --> 00:22:03,780 it just work out of the box and easy 597 00:22:01,980 --> 00:22:05,280 it's very new so you kind of have to say 598 00:22:03,780 --> 00:22:07,320 well I'm going to build with clang 599 00:22:05,280 --> 00:22:09,179 supports webassembly and Wazi just kind 600 00:22:07,320 --> 00:22:11,580 of out of the box but you also need to 601 00:22:09,179 --> 00:22:13,080 provide it the um the sort of wazzy 602 00:22:11,580 --> 00:22:15,600 implementation of the of the C library 603 00:22:13,080 --> 00:22:17,280 and NEC uh other other C libraries that 604 00:22:15,600 --> 00:22:18,960 you want to be you use they have to be 605 00:22:17,280 --> 00:22:20,880 compiled to webassembly and then also 606 00:22:18,960 --> 00:22:24,240 compiled in 607 00:22:20,880 --> 00:22:27,840 um but what you get out is just a wasm 608 00:22:24,240 --> 00:22:29,159 file right I just python.wasm which you 609 00:22:27,840 --> 00:22:32,360 can then just run on the command line 610 00:22:29,159 --> 00:22:34,980 with wasm time but if I actually run 611 00:22:32,360 --> 00:22:38,039 python.wasm with resin time like this I 612 00:22:34,980 --> 00:22:41,760 get this high like whole giant error 613 00:22:38,039 --> 00:22:42,600 message uh that's coming out there 614 00:22:41,760 --> 00:22:44,039 um 615 00:22:42,600 --> 00:22:47,220 can anyone tell me what's going on here 616 00:22:44,039 --> 00:22:48,960 does anyone debug this for me 617 00:22:47,220 --> 00:22:50,400 I don't have my libraries exactly 618 00:22:48,960 --> 00:22:54,000 perfect 619 00:22:50,400 --> 00:22:55,140 um python so in this example I do 620 00:22:54,000 --> 00:22:57,720 actually have the libraries the 621 00:22:55,140 --> 00:23:00,419 libraries are there in a folder uh but 622 00:22:57,720 --> 00:23:03,059 python osm cannot access those libraries 623 00:23:00,419 --> 00:23:04,919 and this is because 624 00:23:03,059 --> 00:23:07,080 um 625 00:23:04,919 --> 00:23:10,380 oh I changed the slider it doesn't work 626 00:23:07,080 --> 00:23:12,539 um so the wazzy API is built with 627 00:23:10,380 --> 00:23:14,880 security and sandboxing in mind from the 628 00:23:12,539 --> 00:23:17,520 beginning so when you're using the Wazi 629 00:23:14,880 --> 00:23:19,140 API there's a set of capabilities that 630 00:23:17,520 --> 00:23:21,240 you can grant to a webassembly program 631 00:23:19,140 --> 00:23:23,580 when you run it if it needs to read the 632 00:23:21,240 --> 00:23:25,200 file system you have to tell it hey you 633 00:23:23,580 --> 00:23:27,299 have access to read the file system you 634 00:23:25,200 --> 00:23:29,940 have this directory or this specific 635 00:23:27,299 --> 00:23:31,559 file you have access to that file and 636 00:23:29,940 --> 00:23:33,240 nothing else if you want to read or 637 00:23:31,559 --> 00:23:34,440 write a particular file you grant it 638 00:23:33,240 --> 00:23:36,000 access if you want to access a network 639 00:23:34,440 --> 00:23:38,580 you have to grant that as a permission 640 00:23:36,000 --> 00:23:41,159 uh to the webassembly program that 641 00:23:38,580 --> 00:23:42,840 you're running so if we do this we tell 642 00:23:41,159 --> 00:23:45,840 it hey this is where the python path is 643 00:23:42,840 --> 00:23:47,640 and this map dough is saying the current 644 00:23:45,840 --> 00:23:49,140 directory which is where all of my C 645 00:23:47,640 --> 00:23:52,740 python code is and where all of my 646 00:23:49,140 --> 00:23:55,440 libraries are should be at the root 647 00:23:52,740 --> 00:23:59,039 directory when I'm running in wasm 648 00:23:55,440 --> 00:24:01,080 uh then I can grant python access to all 649 00:23:59,039 --> 00:24:02,220 the libraries that it actually needs 650 00:24:01,080 --> 00:24:04,020 um if you have a program that doesn't 651 00:24:02,220 --> 00:24:05,760 need to have access to a bunch of files 652 00:24:04,020 --> 00:24:08,340 this is much easier you don't have to do 653 00:24:05,760 --> 00:24:09,960 this but for running python it needs to 654 00:24:08,340 --> 00:24:11,039 have access to the library files or it 655 00:24:09,960 --> 00:24:14,640 can't run 656 00:24:11,039 --> 00:24:16,500 but this folder with the if I have the 657 00:24:14,640 --> 00:24:19,500 folder with the library files and my 658 00:24:16,500 --> 00:24:20,880 python.wasm build of python I could take 659 00:24:19,500 --> 00:24:23,159 that and run that on any machine that 660 00:24:20,880 --> 00:24:24,900 has wasm time installed okay any machine 661 00:24:23,159 --> 00:24:27,120 that has was in time or a different web 662 00:24:24,900 --> 00:24:29,159 assembly engine 663 00:24:27,120 --> 00:24:30,480 so I kind of have this right it's early 664 00:24:29,159 --> 00:24:31,679 days the standard is still under 665 00:24:30,480 --> 00:24:33,900 development there's lots of things that 666 00:24:31,679 --> 00:24:36,659 it can't do yet but I can write in any 667 00:24:33,900 --> 00:24:38,580 language I can compile it to a wasm file 668 00:24:36,659 --> 00:24:40,260 or wasm there are also wasm Docker 669 00:24:38,580 --> 00:24:41,880 containers as well 670 00:24:40,260 --> 00:24:44,580 um which would then bundle the files in 671 00:24:41,880 --> 00:24:46,980 as well and then I can run that in a way 672 00:24:44,580 --> 00:24:49,500 that's secure and sandboxed and limited 673 00:24:46,980 --> 00:24:51,659 to what it needs to be able to do on my 674 00:24:49,500 --> 00:24:52,740 machine and nothing else 675 00:24:51,659 --> 00:24:54,419 so 676 00:24:52,740 --> 00:24:55,620 maybe once this becomes a little bit 677 00:24:54,419 --> 00:24:58,200 more streamlined a little bit easier to 678 00:24:55,620 --> 00:25:00,480 use I will be able to fulfill both of my 679 00:24:58,200 --> 00:25:02,640 aspirational dreams which is very cool 680 00:25:00,480 --> 00:25:04,559 so where are we at the moment what can't 681 00:25:02,640 --> 00:25:07,440 webassembly do 682 00:25:04,559 --> 00:25:08,400 um so M scripting has 683 00:25:07,440 --> 00:25:12,000 um 684 00:25:08,400 --> 00:25:13,679 like a bunch of limitations but uh wazzy 685 00:25:12,000 --> 00:25:15,120 like it can read and write the local 686 00:25:13,679 --> 00:25:16,320 file system it can do sockets and 687 00:25:15,120 --> 00:25:17,820 networking 688 00:25:16,320 --> 00:25:20,039 um I forgot to mention before NM 689 00:25:17,820 --> 00:25:22,080 scripting you can kind of do sockets and 690 00:25:20,039 --> 00:25:24,360 networking but it has it needs a proxy 691 00:25:22,080 --> 00:25:25,559 server that it opens a websocket too and 692 00:25:24,360 --> 00:25:27,419 then the proxy server is actually 693 00:25:25,559 --> 00:25:29,159 handling all the network stuff 694 00:25:27,419 --> 00:25:32,340 um I've not managed to get this to work 695 00:25:29,159 --> 00:25:33,539 even with an example um for myself I 696 00:25:32,340 --> 00:25:34,620 sort of managed to get it to work a 697 00:25:33,539 --> 00:25:36,360 little bit but not really it doesn't 698 00:25:34,620 --> 00:25:38,520 work in C python 699 00:25:36,360 --> 00:25:40,679 um that part hasn't been accomplished 700 00:25:38,520 --> 00:25:43,080 yet it's but you would need a proxy 701 00:25:40,679 --> 00:25:45,419 server anyway for it to run in a browser 702 00:25:43,080 --> 00:25:48,000 but for wazzy it does support sockets 703 00:25:45,419 --> 00:25:49,559 and networking if you're using other C 704 00:25:48,000 --> 00:25:52,320 libraries especially if they're kind of 705 00:25:49,559 --> 00:25:54,900 operating system specific things they're 706 00:25:52,320 --> 00:25:56,460 unlikely to work in Wazi sdl2 doesn't 707 00:25:54,900 --> 00:25:58,500 work nyz 708 00:25:56,460 --> 00:25:59,880 um if you are trying if you have some 709 00:25:58,500 --> 00:26:01,860 kind of C program that you're trying to 710 00:25:59,880 --> 00:26:05,640 make working webassembly 711 00:26:01,860 --> 00:26:08,039 um have a close look at exactly what uh 712 00:26:05,640 --> 00:26:10,500 webassembly the wazier API supports and 713 00:26:08,039 --> 00:26:12,539 whether you need anything else for it 714 00:26:10,500 --> 00:26:14,700 sometimes you'll find like when we're 715 00:26:12,539 --> 00:26:17,400 trying to add support for zedlib and 716 00:26:14,700 --> 00:26:19,740 check if that worked in Python with Wazi 717 00:26:17,400 --> 00:26:20,940 because python depends on zedlib to do 718 00:26:19,740 --> 00:26:22,679 zipping 719 00:26:20,940 --> 00:26:25,200 um you could just compile it for Wazi 720 00:26:22,679 --> 00:26:27,539 and then link it in and it just kind of 721 00:26:25,200 --> 00:26:29,159 worked uh which was amazing because it 722 00:26:27,539 --> 00:26:31,380 doesn't need any operating system access 723 00:26:29,159 --> 00:26:33,000 so but if you do need to do more 724 00:26:31,380 --> 00:26:34,500 operating system access things then the 725 00:26:33,000 --> 00:26:36,179 library's probably explicitly have to 726 00:26:34,500 --> 00:26:39,299 support wazzy 727 00:26:36,179 --> 00:26:42,059 um until maybe the sort of wazzy API 728 00:26:39,299 --> 00:26:43,679 will develop for them okay 729 00:26:42,059 --> 00:26:44,880 um where can we find webassembly it's 730 00:26:43,679 --> 00:26:46,740 currently in use in a bunch of different 731 00:26:44,880 --> 00:26:48,659 places in particular it's used on the 732 00:26:46,740 --> 00:26:51,179 web you've probably used it in websites 733 00:26:48,659 --> 00:26:52,799 if you visited figma uses it uh the new 734 00:26:51,179 --> 00:26:54,539 Photoshop running in the browser makes 735 00:26:52,799 --> 00:26:56,460 quite extensive use of webassembly to 736 00:26:54,539 --> 00:26:58,620 Port some of their Photoshop stuff to 737 00:26:56,460 --> 00:27:00,360 work in the browser as well uh there's 738 00:26:58,620 --> 00:27:03,240 this really cool example of uh someone's 739 00:27:00,360 --> 00:27:04,919 built an entirely emulated x86 32-bit 740 00:27:03,240 --> 00:27:06,240 machine 741 00:27:04,919 --> 00:27:07,860 um that runs in the browser and 742 00:27:06,240 --> 00:27:09,539 webassembly and you can load whatever 743 00:27:07,860 --> 00:27:11,340 like operating system image you want 744 00:27:09,539 --> 00:27:13,559 onto there so this is Windows 2000 745 00:27:11,340 --> 00:27:15,840 running in my browser that is my own 746 00:27:13,559 --> 00:27:16,620 beautiful artwork right there 747 00:27:15,840 --> 00:27:18,419 um 748 00:27:16,620 --> 00:27:20,340 so lots of webassembly is happening on 749 00:27:18,419 --> 00:27:22,620 the web it's also starting to make 750 00:27:20,340 --> 00:27:24,419 Headway into the cloud it has potential 751 00:27:22,620 --> 00:27:27,179 it's not quite in a lot of use yet 752 00:27:24,419 --> 00:27:30,120 cloudflare supports webassembly workers 753 00:27:27,179 --> 00:27:33,000 um there's a wasm edge project they 754 00:27:30,120 --> 00:27:35,220 claim uh that it will be potentially 100 755 00:27:33,000 --> 00:27:37,200 times faster and start up 20 faster at 756 00:27:35,220 --> 00:27:38,340 runtime than Linux containers I'm not 757 00:27:37,200 --> 00:27:39,600 entirely sure how they're making that 758 00:27:38,340 --> 00:27:41,880 comparison 759 00:27:39,600 --> 00:27:43,559 um but yes smaller containers because 760 00:27:41,880 --> 00:27:45,779 it's just your webassembly binary that 761 00:27:43,559 --> 00:27:47,940 you need not an entire like Docker 762 00:27:45,779 --> 00:27:49,919 Container full of Linux files 763 00:27:47,940 --> 00:27:51,600 um for that so there was potential for 764 00:27:49,919 --> 00:27:53,580 this to be huge in cloud computing 765 00:27:51,600 --> 00:27:55,320 because you have this sandboxing without 766 00:27:53,580 --> 00:27:57,720 having to run small lightweight virtual 767 00:27:55,320 --> 00:27:59,340 machines because the sandboxing is built 768 00:27:57,720 --> 00:28:01,440 into the webassembly engine 769 00:27:59,340 --> 00:28:03,659 Okay the third one which I'm super 770 00:28:01,440 --> 00:28:07,080 excited about is sort of replacing 771 00:28:03,659 --> 00:28:09,240 native modules in other runtimes so as 772 00:28:07,080 --> 00:28:11,400 an M1 user I often find that python 773 00:28:09,240 --> 00:28:13,980 packages don't have great support for 774 00:28:11,400 --> 00:28:15,840 the native compiled modules because even 775 00:28:13,980 --> 00:28:16,919 though it's python there's some C code 776 00:28:15,840 --> 00:28:18,179 or something else in there that's 777 00:28:16,919 --> 00:28:19,500 compiled that needs to have every 778 00:28:18,179 --> 00:28:21,900 different platform and operating system 779 00:28:19,500 --> 00:28:24,059 supported and if it doesn't support M1 780 00:28:21,900 --> 00:28:27,419 Max because they're relatively new then 781 00:28:24,059 --> 00:28:29,520 I'm kind of stuck uh and so this is why 782 00:28:27,419 --> 00:28:32,100 I'm super excited about the next talk 783 00:28:29,520 --> 00:28:34,559 that's coming up right now 784 00:28:32,100 --> 00:28:36,900 um which Jim is giving which is about 785 00:28:34,559 --> 00:28:39,779 including like essentially you don't 786 00:28:36,900 --> 00:28:42,059 need to create 70 different 27 different 787 00:28:39,779 --> 00:28:44,700 wheels for different platforms to have 788 00:28:42,059 --> 00:28:46,320 native code in a python package you 789 00:28:44,700 --> 00:28:47,820 could include webassembly instead and 790 00:28:46,320 --> 00:28:51,120 just have one package that works 791 00:28:47,820 --> 00:28:52,500 everywhere so I'm excited about that 792 00:28:51,120 --> 00:28:55,700 um and so you should stick around for 793 00:28:52,500 --> 00:28:55,700 the next talk thank you very much 794 00:28:57,299 --> 00:29:00,020 foreign 795 00:29:00,710 --> 00:29:04,400 [Applause]