Skip to content

Commit

Permalink
chore(perf): improve kayle innate baseline
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 2, 2023
1 parent bdd8af7 commit 80b7591
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 91 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ const results = await autoKayle({
# Measurement is only calculated from the runner and not the extra latency to get the page initially. View the `innate` test to see more detals.

# puppeteer - speed is stable across most versions
# Rust/WASM 18.43487498164177
# Rust/WASM 10.863582968711853
# FAST_HTMLCS 29.915208011865616
# FAST_AXE 162.87204200029373
# ACE 512.5237080156803

# playwright - the speed depends on the version
# Rust/WASM TIME 17.60895800590515
# Rust/WASM TIME 10.163457989692688
# FAST_HTMLCS TIME 33.50962498784065
# FAST_AXE TIME 203.2565419971943
# ACE TIME 905.6748749911785
Expand All @@ -92,8 +92,6 @@ const results = await kayle({
});
```

![Images of issues being stored of the to get visual feedback.](https://user-images.githubusercontent.com/8095978/268726837-f362a490-b611-4acf-8cb6-104f58a0a6c7.gif)

## Runners

`kayle` supports multiple test runners which return different results. The built-in test runners are:
Expand Down
70 changes: 17 additions & 53 deletions kayle_innate/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions kayle_innate/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kayle_innate"
version = "0.0.20"
version = "0.0.21"
authors = ["j-mendez"]
edition = "2018"
license = "MIT"
Expand All @@ -12,18 +12,18 @@ crate-type = ["cdylib", "rlib"]

[features]
default = ["console_error_panic_hook", "accessibility"]
accessibility = ["select"]
accessibility = ["cssparser"]

[dependencies]
wasm-bindgen = "0.2.63"
console_error_panic_hook = { version = "0.1.6", optional = true }
wee_alloc = { version = "0.4.5", optional = true }
select = { version = "0.6.0", optional = true }
url = "2.4.0"
lazy_static = "1.4.0"
case_insensitive_string = "0.1.0"
scraper = { version = "0.17.1" }
getrandom = { version = "0.2", features = ["js"] }
cssparser = { version = "0.33.0", optional = true }

[dev-dependencies]
wasm-bindgen-test = "0.3.37"
Expand Down
59 changes: 28 additions & 31 deletions kayle_innate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@ extern crate lazy_static;

mod utils;
// mod engine;

use case_insensitive_string::CaseInsensitiveString;
use std::collections::HashSet;
use utils::{convert_abs_path, convert_base_path, domain_name, set_panic_hook};
use wasm_bindgen::prelude::*;

#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[cfg(feature = "accessibility")]
use std::collections::BTreeMap;

#[cfg(feature = "accessibility")]
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_u32(a: u32);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_many(a: &str, b: &str);
#[wasm_bindgen(js_namespace = Date)]
fn now() -> u32;
}

#[cfg(feature = "accessibility")]
macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}

#[wasm_bindgen]
/// setup a structure tree alg for parsing and find links in document. Allow user to perform hybrid audits realtime.
Expand Down Expand Up @@ -132,25 +150,6 @@ pub fn get_document_links(res: &str, domain: &str) -> Box<[JsValue]> {
pub fn parse_accessibility_tree(
html: &str,
) -> std::collections::BTreeMap<String, Vec<scraper::node::Element>> {
set_panic_hook();
use std::collections::BTreeMap;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
fn log(s: &str);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_u32(a: u32);
#[wasm_bindgen(js_namespace = console, js_name = log)]
fn log_many(a: &str, b: &str);
#[wasm_bindgen(js_namespace = Date)]
fn now() -> u32;
}

macro_rules! console_log {
($($t:tt)*) => (log(&format_args!($($t)*).to_string()))
}

console_log!("Starting accessibility tree parsing. This is incomplete and should not be used in production.");

let t = now();
Expand All @@ -160,11 +159,9 @@ pub fn parse_accessibility_tree(
let mut accessibility_tree: BTreeMap<String, Vec<_>> = BTreeMap::new();
let mut hh = h.tree.nodes();

// measure select parsing doc 1:1 around 10ms
while let Some(node) = hh.next() {
if let Some(element) = node.value().as_element() {
let element_name = element.name();
// console_log!("{:?}", element_name);
accessibility_tree
.entry(element_name.to_string())
.and_modify(|n| n.push(element.to_owned()))
Expand All @@ -179,15 +176,15 @@ pub fn parse_accessibility_tree(
accessibility_tree
}


#[wasm_bindgen]
#[cfg(feature = "accessibility")]
/// audit a web page passing the html and css rules.
pub fn _audit_not_ready(html: &str, _css_rules: &str) {
set_panic_hook();
// parse css first
let _css_nodes = cssparser::Parser::new(&mut cssparser::ParserInput::new(&_css_rules));
// build tree
let _tree = parse_accessibility_tree(&html);
let _css_nodes = parse_css(_css_rules);
// reference the css model when in the tree to get style information
}

/// parse css tree to maps
pub fn parse_css(_css: &str) {
// parse the css to a list of nodes capable of o1 getting results
}
// send tree with css parser to parse conditions fast.
}

0 comments on commit 80b7591

Please sign in to comment.