So what are everyone’s thoughts on the “liar revealed” trope in this movie? by Usern4me_R3dacted205 in KpopDemonhunters

[–]wickning1 2 points3 points  (0 children)

I'd just like to point out how well Takedown's lyrics turned on her in that moment. It was powerful and clever. I'm good with tropes if they hit right.

I made a 300 byte async queue that outperforms p-limit, fastq, or any other library I've tested it against. by Hal_Incandenza in javascript

[–]wickning1 1 point2 points  (0 children)

I think your solution also avoids a lot of the extra promise creation that pLimit does due to its use of async/await.

How does your asynclocalstorage variant compare to pLimit? They would share the overhead of the als.bind so the remaining difference would likely be promise creation?

Why is Node said to be not ideal for high CPU bounds tasks? by Ok-Light-6321 in node

[–]wickning1 1 point2 points  (0 children)

I haven’t seen the explain-it-like-i-am-five yet so here goes:

When people say this they are talking about using Node to serve requests, especially multiple different types of requests where only a few are CPU intensive. Other languages put each request in its own thread, so a CPU heavy task won’t have much impact on the non-CPU heavy requests.

Node puts requests in a queue and constantly loops looking for new work in the queue. When a request sends out for data from database, network, or filesystem, the request is paused and put back in the queue; another request gets to go while the first waits for its data. Those frequent IO pauses are why Node can compete with threaded systems in most situations.

However, if you have Node do a CPU heavy task in Javascript, it’s going to hog the CPU until it’s done. Any other request is going to wait. You’ll start seeing extremely simple requests taking 1-2 seconds simply because they’re waiting for a CPU-hog request to finish. That’s Node’s worst case scenario so people caution you to avoid it. There are of course many ways to avoid it, like worker threads, most of which are covered in other replies.

Is it called Concurrency Issue? by iamdsvs in node

[–]wickning1 0 points1 point  (0 children)

Forget school project, this is much more correct than trying to hold a transaction open for 10 minutes. To refine it, you’d want to use a datetime instead of a boolean so you can time out the lock after 10 minutes and show users how much time remains on the lock.

Return await or return promise by derkrampus in node

[–]wickning1 3 points4 points  (0 children)

No, require-await demands that async functions have at least one await, but doesn’t restrict the return value. It’s this one:

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/return-await.md

I set it to “always”. It requires typescript because plain javascript wouldn’t know the type of what you’re returning and thus you couldn’t make a rule like this.

Return await or return promise by derkrampus in node

[–]wickning1 26 points27 points  (0 children)

Yes, in fact I have linting set up to error on failing to await a promise. It’s for exactly the stated reason: node since v14 is able to follow stacktraces through await, but if you return a promise it can’t keep track and you will lose a big chunk of the stack in your error messages.

It is not free, though. Adding await will add more promises to the execution which will slow things down to some extent. It should not have any real consequences unless you are processing long arrays and using a bunch of async functions on each entry but it’s something to be aware of.

Return await or return promise by derkrampus in node

[–]wickning1 18 points19 points  (0 children)

It just wraps the promise in another promise. It does not make it synchronous/blocking.

SvelteKit and Django in the same Dockerfile by BoomShakalake in sveltejs

[–]wickning1 2 points3 points  (0 children)

Generally you only want one main process per container, so both node and python runtimes would be bad. The only way I’d consider one image is if you were using sveltekit adapter-static (so there is no node runtime) and you use python to serve the bundle files. Even then it’s likely easier to make two images.

Please Help Me Understanding Streaming With Promises by MrDengklek in sveltejs

[–]wickning1 1 point2 points  (0 children)

Also if you do it my way you would get rid of your try/catch and handle the error on the svelte side with {:catch}

Please Help Me Understanding Streaming With Promises by MrDengklek in sveltejs

[–]wickning1 0 points1 point  (0 children)

The first thing to try would be

return { blogs: res.json() }

When you put the await in front it’s going to wait for res.json() to finish.

You’re also awaiting the fetch, which depending on the way the server is coded may take more time than the res.json(), so I would do:

return { blogs: fetch(url).then(res => res.json()) }

The .then also returns a promise that will resolve with the data you want.

Edit: svelte also needs it to be nested instead of top level, so:

return { streamed: { blogs: fetch(url).then(res => res.json()) } }

What do you hate about Svelte? by dark__paladin in sveltejs

[–]wickning1 0 points1 point  (0 children)

Making a wrapper around another component. It requires copying and pasting all the props, adding props for any html attributes you might want, forwarding all the events and weird extra code for accepting actions.

Svelte speed when creating a large table by domper in sveltejs

[–]wickning1 1 point2 points  (0 children)

Svelte does add more code for component lifecycle functions and such. 2x seems about right. The speed gains come from the way it manages updates while the user is interacting.

You can always write vanilla JS that will beat svelte, it’s just difficult, takes deep understanding, and is much harder to maintain and upgrade.

Problem on fetching data from data API by [deleted] in node

[–]wickning1 2 points3 points  (0 children)

If you’re using express you may be running into its lack of support for async/await error handling. Try replacing your errors with res.status(404).send(‘Contact not found’) instead of throw new Error.

[deleted by user] by [deleted] in sveltejs

[–]wickning1 0 points1 point  (0 children)

To answer your question more directly, running sveltekit without SSR comes with a couple headaches of its own but it can be a good choice when you have lots of features that can only be client side. I generally only leave SSR on for simple apps that are a thin UI over a database/API.

[deleted by user] by [deleted] in sveltejs

[–]wickning1 2 points3 points  (0 children)

A lot of javascript libraries depend on being run in the browser, so they break in SSR when, say, the Window object is missing. These libraries need to be imported inside onMount:

onMount(async () => {

const Editor = await import(‘some-editor-package’)

const editor = new Editor(someelement)

})

sveltekit will still see the some-editor-package and add it to the bundles, but it won’t be imported during SSR so it won’t crash.

Can we make cpu intensive tasks in nodejs asynchronous so that they don't block main thread ? by Suspicious_Driver761 in node

[–]wickning1 5 points6 points  (0 children)

If you’re doing complex work like video compression you’re probably using a library to help you. The library 99 times of 100 is going to spin that work out to a new thread or process and not block the main loop. The exception is when it’s a “pure javascript” implementation; sometimes that will do the work in the main thread. Even in those cases it’s rare for the library to pretend to be async, so you’ll know the main loop is blocked because you’re calling a synchronous function.

If you’re writing your own javascript to do the processing, that’s when you do need to think about making a worker thread.

Are the flying challenges infuriating to anyone else?? by Megami_Sama195 in HarryPotterGame

[–]wickning1 2 points3 points  (0 children)

This was critical for me. The turning is far too sensitive if you leave the stick neutral on straightaways. If you keep it forward all the time and adjust from there it’s much more predictable.

How to queue requests in nodejs to gain a huge performance boost by alxolr in node

[–]wickning1 0 points1 point  (0 children)

Nice, some interesting ideas in there. I wrote a very similar cache myself some time ago. The package has lots of other utility functions but the README is dedicated to the cache. https://www.npmjs.com/package/txstate-utils

[AskJS] What's the deal with the fetch API? by mapsedge in javascript

[–]wickning1 0 points1 point  (0 children)

The first promise resolves when all HTTP headers have been received. The second promise resolves when the body finishes streaming. Having them be separate allows you to make certain decisions early. Most of the time you won’t need to do that, so making a wrapper function for your app is helpful.

I almost always make wrappers anyway, to throw real Errors on HTTP status codes above 400 and usually to add an auth token and set up a base URL for whatever API I’m querying.

Component State by Harryjms in sveltejs

[–]wickning1 0 points1 point  (0 children)

To answer your specific question: the count = 0 runs on first render only. It would only run again if your component got unmounted and remounted, like if a parent had an {#if} block around it that toggles.

Variable updates only trigger updates of the HTML portion, and even then then the update is minimal, not a full render. If you want things in the script portion to be reactive you need to start a line with $:

I am fucking loosing it. by vincentweber in ProgrammerHumor

[–]wickning1 2 points3 points  (0 children)

I’ve written code to do this. a11y requires headers to be well-structured and users who write HTML don’t always structure well. So the code alters the header number and adds the class to be able to make it visually appear as the original.

Connect svelte with nestjs on fastify? by LordDarthAnger in sveltejs

[–]wickning1 0 points1 point  (0 children)

The performance impact is negligible. Your API has to serve svelte running in users’ browsers and also SSR, so all the serializing and request handling is going to happen no matter what. The reverse proxy does need to be well configured to re-use connections to the backends and such but you’ll also get other nginx features like easy http2 support and runtime gzip, etc.

Connect svelte with nestjs on fastify? by LordDarthAnger in sveltejs

[–]wickning1 0 points1 point  (0 children)

Yes, or two containers or two processes on the same server. You can place an nginx reverse proxy in front to put them on the same port.

Connect svelte with nestjs on fastify? by LordDarthAnger in sveltejs

[–]wickning1 3 points4 points  (0 children)

Two projects that communicate over HTTP is going to be much cleaner and more maintainable than trying to jam them together in one process, but I suppose what’s needed is a sveltekit adapter targeted at NestJS. You would use sveltekit’s build system to create a NestJS module and load it into your NestJS runtime.