Skip to content

Instantly share code, notes, and snippets.

View lastmjs's full-sized avatar

Jordan Last lastmjs

View GitHub Profile
@lastmjs
lastmjs / gist:d058b2c8133b1cf45262883b3429b1be
Last active June 15, 2024 00:45
Boa/QuickJS Benchmarks Comparison
This compares Boa and QuickJS against these benchmarks: https://bellard.org/quickjs/bench.html
From these numbers we have evidence to believe that Azle's performance can be improved ~28x by switching to QuickJS.
We also have evidence from https://bellard.org/quickjs/bench.html that QuickJS could be improved up to 2x without compilation/JIT, and that compiled languages have one order of magnitude improvement over interpreted languages.
Boa:
target/release/boa combined.js
PROGRESS Richards
#![allow(warnings, unused)]
use azle_vm_value_derive::{CdkActTryIntoVmValue, CdkActTryFromVmValue};
use candid::{Decode, Encode};
use rand::Rng as _AzleTraitRng;
use slotmap::Key as _AzleTraitSlotMapKey;
use std::convert::TryInto as _AzleTraitTryInto;
use std::str::FromStr as _AzleTraitFromStr;
thread_local! {
static BOA_CONTEXT_REF_CELL : std::cell::RefCell < boa_engine::Context < 'static >> =
{ struct Hooks; impl boa_engine::context::HostHooks for Hooks { fn utc_now(& self) ->
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ahash"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
dependencies = [
@lastmjs
lastmjs / block-full-stack-mentor-assessment.md
Last active August 25, 2019 18:11
Full Stack Mentor - Candidate Assessment

JavaScript

Hey Student,

Oh dear, this is a tricky one. It's definitely messed me up in the past. What's happening here is an issue of scoping and closures. A few things to point you in the right direction:

  1. Study block scoping versus function scoping in JavaScript
  2. Study JavaScript's variable declarators, var, let, and const, and understand the differences between their uses
  3. Study up a bit on closures in JavaScript
  4. With your new knowledge, try to make btnNum block scoped instead of function scoped
const ultimateSchemaString = mergeTypes([
readFileSync('./schema/datamodel.graphql').toString(),
readFileSync('./schema/dataops.graphql').toString(),
readFileSync('./schema/directives.graphql').toString(),
readFileSync('./generated/prisma.graphql').toString()
], {
all: true
});
const ultimateSchema = makeExecutableSchema({
typeDefs: ultimateSchemaString,
directive @userOwns(field: String) on FIELD | FIELD_DEFINITION
directive @authenticated on FIELD | FIELD_DEFINITION
directive @private on FIELD | FIELD_DEFINITION
# This is where we define any custom resolvers, and where we add custom directives to any generated Prisma resolvers
type AuthPayload {
token: String!
user: User!
}
type Mutation {
# Custom resolvers
signup(email: String!, password: String!): AuthPayload!
# All types defined here will be fed through the Prisma generation process
# Essentially, all of these types become database tables
type User {
id: ID! @unique
createdAt: DateTime! @private
updatedAt: DateTime! @private
email: String! @unique @userOwns(field: "id")
password: String! @private
}
export async function privateDirectiveResolver(next, source, args, context) {
throw new Error('Private');
}
export async function authenticatedDirectiveResolver(next, source, args, context) {
if (getUserId(context)) {
return await next();
}
else {
throw new Error('Not authenticated');
}
}